Added ssh-with-timeout for ssh-agent usage with password-protected keys

This commit is contained in:
Autumn Naber
2026-01-30 13:51:18 -08:00
parent 2702cfdd64
commit 86beb728e8
4 changed files with 37 additions and 10 deletions

31
ssh-with-timeout.sh Executable file
View 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 $@