Last active
August 17, 2023 06:02
-
-
Save ryanwoodsmall/6bc83ddfea2cba0c41bc95d8b8a8663a to your computer and use it in GitHub Desktop.
ssh-agent-helper.bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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