Thursday, January 21, 2010

Setting up TortoiseGit to work with SSH on a different port (not port 22)

So recently we've had some headaches giving users on Windows machines access to our git repository (me being one of them but not the first). In searching for a solution to this problem I found several people with the same issue but having to use various workarounds or actually change their ssh port back to 22. All of the workarounds were out of the question for me but I knew there had to be a way to do it. Basically I just followed some of the better posts about using Git on Windows out there with a couple minor changes.

Here are links to a few of the posts I looked at while trying to figure this out:

The important pieces to make sure you get it working are these:
  1. Be sure you choose the OpenSSH option when installing msysgit
  2. Be sure you choose the OpenSSH option when installing TortoiseGit
  3. create a .ssh/config file and enter something like the following
Host name_of_host_where_your_git_repo_is
User git
Hostname name_of_host_where_your_git_repo_is
Port port_number
PreferredAuthentications publickey
IdentityFile "/path/to/your/openssh/private/key"
And you should be good to go. I actually set up msysgit and my ssh config file first, then I made sure that I could connect and then I installed TortoiseGit.

Tips:
  1. If you created your private key using puttygen then you'll need to export it (using puttygen) as an OpenSSH key.
  2. While testing your connection you can use ssh -v git@github.com (or @ your own host even) to see what ssh is doing and to make sure it is finding your key correctly.
  3. If your openssh key is located at C:\users\myuser\keys\key.ssh then the path to your IdentityFile should be like this: /c/users/myuser/keys/key.ssh