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

View File

@@ -15,5 +15,6 @@ unset SSH_ASKPASS
eval "`dircolors -b $DIR_COLORS`" eval "`dircolors -b $DIR_COLORS`"
export PATH=$PATH:$HOME/.local/bin export PATH=$PATH:$HOME/.local/bin
alias ssh=$HOME/.local/bin/ssh-with-timeout.sh
#### END MAGIC VALUE: AZSQFRB8 #### END MAGIC VALUE: AZSQFRB8

View File

@@ -18,13 +18,8 @@
default = simple default = simple
[core] [core]
editor = vim editor = vim
sshCommand = /home/anaber/.local/bin/ssh-with-timeout.sh
[pull] [pull]
ff = only ff = only
[http] [http]
postBuffer = 524288000 postBuffer = 524288000
sslcainfo = /etc/ssl/certs/ca-certificates.crt
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

View File

@@ -25,7 +25,7 @@ done
echo "Copying scripts" echo "Copying scripts"
mkdir -p "${HOME}/.local/bin" mkdir -p "${HOME}/.local/bin"
script_copy_list=(update-dns.sh gentags) script_copy_list=(update-dns.sh gentags ssh-with-timeout.sh)
for script in ${script_copy_list[@]}; do for script in ${script_copy_list[@]}; do
cp -fr "${script}" "${HOME}/.local/bin/${script}" cp -fr "${script}" "${HOME}/.local/bin/${script}"
done done

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 $@