-
-
Save axelabs/066351eecfc9349527230d1fa0cb3eae to your computer and use it in GitHub Desktop.
Re-use ssh agent cross logins.
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
# To use this, source from your proFile. | |
MYAGENTS=(`pgrep -U $USER -f ^ssh-agent$|sort -n`) | |
echo "Found ${#MYAGENTS[@]} ssh-agents." | |
# Let's try to take over the agents, like we do everynight Pinky! | |
if [[ "${MYAGENTS[@]}" ]];then | |
KEEPER=${MYAGENTS[0]} | |
echo KEEPER: $KEEPER | |
OUTCAST=${MYAGENTS[@]:1} | |
[[ "$OUTCAST" ]] && { echo "Goodbye agent $OUTCAST"; kill $OUTCAST; } | |
SSH_AUTH_SOCK=`awk '/tmp\/ssh/ {print $NF}' /proc/$KEEPER/net/unix` | |
export SSH_AUTH_SOCK; | |
SSH_AGENT_PID=$KEEPER; export SSH_AGENT_PID; | |
else | |
NEWAGENT="`ssh-agent`" | |
echo $NEWAGENT; | |
eval $NEWAGENT | |
fi | |
ssh-add -l | grep "The agent has no identities" && ssh-add |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment