Cygwin: ssh-add can’t find id_dsa

21 February 2012

I recently found myself in a position to try out Cygwin again, to get my hands on the unix tools I love on Windows 7.  So far I’ve been pleased with the experience, and will take cygwin over putty any day.  I did hit a couple bumps though, and one I couldn’t find an answer to online, so I wanted to throw my own answer up here in case someone else encounters it.

For reference, I’m using cygwin 3.0-1, and OpenSS _5.9p1.  My second issue appears to be a bug, so hopefully it will get fixed soon.

The first problem is getting ssh-agent running and working.  The copy-pasta below that is all over the internet worked for me.  Add to the bottom of your ~/.bash_profile:

if [ -z “$SSH_AUTH_SOCK” -a -x “$SSHAGENT” ]; then
trap “kill $SSH_AGENT_PID” 0

The next problem I had was that `ssh-add` failed to find my ~/.ssh/id_dsa private key.  The man page states very explicitly that it should be looking there, but it wasn’t.  If I specified the key on the command line with ssh-add, it would add it successfully.  Permissions looked right, with 700 on ~/.ssh and 600 on ~/.ssh/id_dsa.  The command that helped me figure it out finally was:

$ ssh-add -vT

[a bunch of garbage followed by]

debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug1: key_parse_private_pem: PEM_read_PrivateKey failed

Those middle two lines show that rather than looking for ~/.ssh/id_dsa in my home directory, ssh-add is instead looking in the root of the file system for a .ssh/ directory.  Strange!  I used a simple hack to straighten it out:

ln -s /home/username/.ssh /

The symlink helps ssh-add find my private key without having to manually specify it every time.  This wouldn’t be a full solution on a true multiple-user system — but like I said, I’m on Windows.  ;)

This entry was posted on 21 February 2012 and is filed under Tech Support.

Comments are closed.