git, ssh, windows

Work in progress

  • I’ll add screenshots
  • Link to instructions on Github, Gitorous and Bitbucket

TL;DR

  • With PuTTY tools setup SSH key-pair, make sure an SSH agent uses the key
  • Get public part of key to the remote git repo, make sure it works
  • Install msysgit and during installation, opt for PuTTY

Since this happens quiet often, I just thought I’d write up the setup here.

Setting up SSH

Generate a key pair

Get PuTTY installer for your platform and install all the tools. Start the PuTTY key generator and select RSA-type and bit length of 2048 bits (or longer). Enter a passphrase for the key you’re generating. The passphrase can be changed whenever you want to, as long as you remember it. You typically only need to enter it once per desktop session (login/logout, reboot) so it’s OK to pick a long and rememberable sentence. Final step: save the key pair somewhere locally. You don’t want to expose this keypair, although it should be safe for the next x years. The public part of the key however, you can distribute freely and send to anyone anywhere. On its own, the public key part is totally useless – it can only used to verify that you have access to the private key, nothing else.

  • The key pair is protected with a passphrase
  • The key pair is saved on your disk
  • The public part of the key is saved somewhere as well, probably next to the key pair file. (This public part is what you add to your account on Github, gitorous, bitbucket etc, it looks something like this: http://wendt.se/ssh/)

Starting a key agent

A key agent “unlocks” the private part of the keys it handles, and enables other programs, such as git, to use the keys for authentication without needing git to worry about how SSH works. So, start the PuTTY key agent, and if possible make sure that it starts every time you log in/start a desktop session. It’s a small program that can be accessed in the taskbar and you should now right click its icon, open it and click “Add key”. Locate the key pair, press OK and enter the passphrase to unlock the key and let the agent handle it until you log out or shut down the key agent.

Get the public part of the key to the Git repository

This is highly dependent on where the git repo is hosted. With a simple Linux host, you’ll simply add your key on one line to the .ssh/authorized_keys file in the account used for git access. You can verify that it works by running PuTTY to the host: start it, enter the hostname, click Connect and enter the username. If all is setup properly with key agent and you’ve added the public part of your key to the account’s authorized_keys, you should be logged in without being asked for a password.

Setting up Git on Windows

Get the installer, run it and when it asks about PuTTY – go for that option. The rest is a “click Next/OK” exercise.

Work that code

Just follow the instructions from the hosting service you use. Make a trivial change (add space, extra line etc), commit and try to push. It should just work.

Leave a Reply

Your email address will not be published. Required fields are marked *

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