Tag Archives: Cygwin

Starting Cygwin ssh-agent at Logon

Common problem: you want to use ssh-agent with Cygwin, but because Windows is special, you can’t inherit the environment in the way you naturally would on a Unix or Linux system.

Now, before I proceed, understand that this is a HorribleHackā„¢; it is the equivalent of modifying your .bashrc every time you login.

For this to work, you need to have the setx utility installed, which you need to download if you’re still using XP.

The first step is to save the following script; I put it in ~/bin/, but you could safely put it into /usr/bin as it only modifes the environment of the person who runs it. I used Python 3 because I could and because everyone should.

Next, create a shortcut in your Startup Folder. I called it simply “SSH Agent”.

The command line you will need (the Target field in the shortcut), is:

There seems to be an undocumented feature of run, that requires one to set the -p option to something or it will fail. Obviously, if you’ve installed the 64-bit version of Cygwin or put the start-ssh-agent script somewhere else, you’ll need to change your paths accordingly.

I haven’t written the symmetrical stop-ssh-agent, because I’m lazy and Windows doesn’t provide a convenient location to run scripts at log-off (you mess with group policies if you want, but I have more interesting things to be doing…)