Created
September 7, 2022 13:41
-
-
Save UnixSage/5a2073ca910818868f2f2adc05ab3d80 to your computer and use it in GitHub Desktop.
Snipit to add to bash_profile that will find an existing ssh-agent or start a new one. Also complains if it finds more than one for a user.
This file contains 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
# Attach to a running ssh-agent or start a new one | |
if [ `find /tmp -maxdepth 1 -name "ssh-*" -user ${USER} | wc -l` == 1 ] ; then | |
echo "Found ssh-agent, attaching.." | |
SSHDIR=`find /tmp -maxdepth 1 -name "ssh-*" -user ${USER}` | |
SSH_AUTH_SOCK=`ls ${SSHDIR}/agent*` ; export SSH_AUTH_SOCK | |
SSH_AGENT_PID=`echo ${SSH_AUTH_SOCK} | awk -F"." '{print $2+1}'` ; export SSH_AGENT_PID | |
echo "Agent pid ${SSH_AGENT_PID}" | |
elif [ `find /tmp -maxdepth 1 -name "ssh-*" -user ${USER} | wc -l` == 0 ] ; then | |
echo "no ssh-agent found, starting.." | |
eval `ssh-agent -t 86400` | |
else | |
echo "####################################" | |
echo "# ssh-sgent in a suspicious state! #" | |
echo "####################################" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment