Tuesday, February 14, 2012

SSH Agent on Cygwin

A blog post from http://blog.killtheradio.net/how-tos/ssh-agent-on-cygwin/ works great on my win7 machine.
Just add this code into ~/.bash_profile to make ssh-agent running every time you open new shell.
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
 eval `$SSHAGENT $SSHAGENTARGS`
 trap "kill $SSH_AGENT_PID" 0
fi
Close your shell and open new window, ssh agent will running on background. Now you can add your private key into ssh-agent using command :
ssh-add ~/.ssh/id_rsa
[enter your password]
You don't have to type any password again to ssh into your server. If you have lot of server with same pub-key on each of it, you can jump to another server from currently login server with same private key. To make this thing works, you have to add another command into your ssh config (~/.ssh/config) :

ForwardAgent yes 
That's all folks!