Side-by-side installation of Cygwin SSH and Git on Windows

I have a Cygwin installation on my Windows box and now I downloaded the lastest Git version (for Windows). Git has a small Cygwin included as well and I thought the two would interact nicely—but they don’t.

The problem is that they use a different layout of mapped drives (i.e., mapped from Windows to the Posix world of Cygwin). My regular Cygwin has its root under C:\cygwin64 and from there, for example, the SSH key directory is under /home/chris/.ssh, whereas Git has its root directory somewhere in the Git installation and the home directory is where the Windows user directory is, i.e., C:\Users\chris and there lies the .ssh directory as well.

I thought some symbolic links would do the trick, so I linked the Git .ssh directory to my (real) .ssh directory in Cygwin.

Nice, but not enough. Now, SSH will not find the keys, since it still wants to load its keys from /c/Users/chris/.ssh, so I added another symbolic link to add the /home directory to Git and map it to the /home of Cygwin and add a symbolic link to /etc/ssh_config and add an IdentityFile /home/chris/.ssh/id_rsa.

Not bad, but still not good enough. This time, Git’s ssh-agent is not able to connect to the already loaded (regular Cygwin) ssh-agent. The reason is that both Cygwin’s have different /tmp directories. When I added the Git version to my regular Cygwin (that is, have /tmp map to the user’s TEMP directory, usually under C:\Users\chris\AppData\Local\Temp) by changing the /etc/fstab file, nothing changed. Calling mount to check if the changes worked showed no changes.

The trick here is: you have to close all programs that use Cygwin: ssh-agent, bash, sshd, mintty, everything. Then reload and Voil√†! Now the proper /tmp is there and it’s the same on both Cygwin’s, ssh-agent can be accessed from both installations and due to the symbolic links both SSH’s use the same config and key files.

Victory at last!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.