I work quite a bit with Git these days and I do that cross-platform. On Windows I tend to use msysgit (with the GIT Bash) since I already know my way around the Git command line and quite frankly, I like it. One of the things I always have to Google together from different sources is how to get an SSH setup that allows me to authenticate with Github and my own repositories using public/private keys.
For this I use the OpenSSH approach since this allows me to use the exact same knowledge and infrastructure on Windows, Linux and Mac and it integrates seamlessly with msysgit. The questions usually revolve around the configuration since the installation is already part of msysgit.
All of the important client configuration for OpenSSH is stored in the user’s home directory in a “.ssh” folder (yes, even on Windows). It can be quite difficult to tell exactly where your home directory is, so I just fire up the Git Bash and type
echo $HOME
If it doesn’t already exist, create a “.ssh” folder in that directory. There are at least three important files (at least for me) that you may have to create.
- The known_hosts file contains a list of SSH hosts you have had connections with with their SSH fingerprints. This file is automatically maintained for you, but in some cases (e.g. if you get the “remote host identification has changed” warning) you may have to manually edit or delete it.
- The config file defines which private key to use for which host to authenticate. It contains a list of host definitions that allows you to specify the host name and private key file you want to use for this host like this:
Host myhostname.com Port 12345 IdentityFile ~/.ssh/myprivatekeyfileforthishost
- One or more private key files
I use Putty’s PuttyGen.exe to create most of my keys, but Putty has its own format to store private keys. If you want to use a Putty key as an OpenSSH key file you have to convert it first. Simply open the key with PuttyGen.exe and select the “Export OpenSSH key” option from the “Conversions” menu – et voilĂ !
With this, you should be able to connect to all your secured Git repositories with msysgit.