Skip to content

Instantly share code, notes, and snippets.

@ryanwoodsmall
Last active August 17, 2023 06:02
Show Gist options
  • Save ryanwoodsmall/6bc83ddfea2cba0c41bc95d8b8a8663a to your computer and use it in GitHub Desktop.
Save ryanwoodsmall/6bc83ddfea2cba0c41bc95d8b8a8663a to your computer and use it in GitHub Desktop.
ssh-agent-helper.bash
#!/usr/bin/env bash
# ssh
export GIT_SSH_COMMAND="ssh -4"
sshagentenv="/tmp/ssh-agent-${USER}.sh"
touch "${sshagentenv}"
. "${sshagentenv}"
if ! $(ps -U "${USER}" | grep -q 'ssh-agent') ; then
eval `ssh-agent -s`
for e in SSH_AGENT_PID SSH_AUTH_SOCK ; do
sed -i "/^export ${e}=.*/d" "${sshagentenv}"
echo "export ${e}=${!e}" >> "${sshagentenv}"
done
unset e
fi
. "${sshagentenv}"
for k in ${HOME}/.ssh/id_* ; do
echo "${k}" | grep -qE '(_dropbear.*|\.pub)$' && continue || true
f="$(ssh-keygen -l -f ${k} | awk '{print $2}')"
ssh-add -l | grep -q "${f}" || ssh-add "${k}"
unset f
done
unset k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment