Added ssh-with-timeout for ssh-agent usage with password-protected keys
This commit is contained in:
31
ssh-with-timeout.sh
Executable file
31
ssh-with-timeout.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
SSH_ENV="$HOME/.ssh/environment"
|
||||
|
||||
function load_key_file {
|
||||
local key_rsp="$(ssh-add -L 2>&1)"
|
||||
if [[ "${key_rsp}" == *"The agent has no identities"* ]]; then
|
||||
ssh-add /home/anaber/.ssh/id_rsa
|
||||
fi
|
||||
}
|
||||
|
||||
function start_ssh_agent {
|
||||
ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
|
||||
}
|
||||
|
||||
if [ ! -e "${SSH_ENV}" ]; then
|
||||
start_ssh_agent
|
||||
. "${SSH_ENV}" > /dev/null
|
||||
else
|
||||
. "${SSH_ENV}" > /dev/null
|
||||
ps -ef | grep ${SSH_AGENT_PID} | grep -q ssh-agent$ || {
|
||||
start_ssh_agent
|
||||
}
|
||||
. "${SSH_ENV}" > /dev/null
|
||||
fi
|
||||
export SSH_AGENT_PID
|
||||
export SSH_AUTH_SOCK
|
||||
|
||||
load_key_file
|
||||
# Pass command line arguments to ssh
|
||||
/usr/bin/ssh $@
|
||||
Reference in New Issue
Block a user