Created
July 8, 2009 07:33
-
-
Save pmakholm/142660 to your computer and use it in GitHub Desktop.
Handle multiple ssh-agents
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
# Shell snipet to handle multiple ssh-agents | |
# | |
# By default I use an ssh-agent with a lot of keys added with the -c option to | |
# ssh-add and this agent is forwarded trough most of my connections. | |
# But for some taske this confirmation step is a hassle, so I create new | |
# agents without confirmation with a minimal set of keys. | |
# | |
# You have to source this "script" to work or use the hack described at | |
# http://peter.makholm.net/2009/07/07/shell-hacks-bash-functions-in-files/ | |
if [ "$1" = "-u" ] ; then | |
UNBOUND=yes | |
shift | |
fi | |
if [ -d "$HOME/.ssh/$1" ] ; then | |
export SSH_AGENT_TAG=${1:-std} | |
SSH_ADD_OPT= | |
case $SSH_AGENT_TAG in | |
std) | |
SSH_ADD_OPT=-c | |
esac | |
if [ -n "$UNBOUND" ] ; then | |
eval $( ssh-agent -s ) | |
ssh-add $SSH_ADD_OPT $HOME/.ssh/$SSH_AGENT_TAG/* | |
else | |
if [ ! -e $HOME/.ssh/$SSH_AGENT_TAG.agent ] ; then | |
eval $( ssh-agent -s -a $HOME/.ssh/$SSH_AGENT_TAG.agent ) | |
ssh-add $SSH_ADD_OPT $HOME/.ssh/$SSH_AGENT_TAG/* | |
else | |
SSH_AUTH_SOCK=$HOME/.ssh/$SSH_AGENT_TAG.agent | |
SSH_AGENT_PID=0 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment