Auto-start of SSH Agent on Cygwin

Here is how to get ssh-agent started automatically every time you run Cygwin. If you’re also burdened with working on a Windows machine all day, having Cygwin at your disposal can be essential.

Until recently I didn’t know Cygwin included ssh-agent; simply typing ssh-add at the command prompt doesn’t start it as it does within most distributions.

First, create a bash profile from within Cygwin, if you don’t already have one:

touch ~/.bash_profile
chmod a+x ~/.bash_profile

Add the following commands to the file:

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

Next time you open Cygwin, you can run ssh-add to load your keys. Maybe best of all, it unloads the authentication agent when your Cygwin session is closed.

All credit and many thanks to the author of the “Kill The Radio” blog (original post)