Skip to content

Instantly share code, notes, and snippets.

@esteigler
Forked from anonymous/gist:3136741
Created July 18, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esteigler/3136772 to your computer and use it in GitHub Desktop.
Save esteigler/3136772 to your computer and use it in GitHub Desktop.
Sort out your SSH Agent sockets
function agentstatus {
echo -n "Agent status: ";
if ssh-add -l &>/dev/null; then
echo "WORKING"
return 0
else
echo "BROKEN";
return 1
fi
}
function lsagent {
for sock in /tmp/ssh-*/agent.*; do
echo "socket: $sock "
if SSH_AUTH_SOCK=$sock ssh-add -l &>/dev/null; then
nidents=$(SSH_AUTH_SOCK=$sock ssh-add -l 2>/dev/null | grep -v ident | wc -l)
echo -e "\tstatus: WORKING"
echo -e "\tidentities: "$nidents"\n"
else
echo -e "\tstatus: BROKEN\n"
fi
done
}
function findagent {
if agentstatus; then
return 0
fi
export res=""
for sock in $(find /tmp -name agent.* -perm 0600 -type socket -user $USER); do
echo "Trying agent sock: $sock"
export SSH_AUTH_SOCK=$sock
res=$sock
if ssh-add -l &>/dev/null; then
agentstatus
return 0
fi
done
agentstatus
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment