Skip to content

Instantly share code, notes, and snippets.

@axelabs axelabs/agent.sh Secret
Last active Jan 23, 2019

Embed
What would you like to do?
Re-use ssh agent cross logins.
# 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
You can’t perform that action at this time.