Setting up SSH for Git on Windows

I’ve found myself having to do this on multiple machines and always seem to miss a step along the way. Over the years, I’ve ended up updating my approach and have updated the post accordingly (mentioning that in case you’re seeing something different from last time you checked this post). Here’s what I currently do: 

  1. Install Git for Windows from here.
  2. Get Putty (including PuttyGen and Pageant) from here.
    • I end up just getting the ZIP file package as I haven’t really needed to properly install the tools. Instead, I drop the files in a folder I have on my OneDrive so it’s on all of my machines.
  3. Open up a command prompt and create a new directory called .ssh in %userprofile%.
    md %userprofile%\.ssh
  4.  Run PuttyGen to generate a new SSH key
    • Remember to set a passphrase to keep things secure.
    • Save the public and private key to the .ssh directory you created in the previous step. I name the key using the PC’s name as that’s how I reference all of my keys on the various services I use these with (e.g., VSTS, GitHub, GitLab, BitBucket).
  5. Set your system’s GIT_SSH environment variable to point to plink.exe (it’s a file that’s included in the Putty package you downloaded in step 2.
  6. Make pageant.exe auto-run on Windows startup (run the following from within the directory you saved the Putty files in):
    reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v Pageant /t REG_SZ /d "\"%cd%\pageant.exe"" /f
  7. Update the registry key you just created to include the path to the key file you just created by appending it to the command-line (yes, this could be merged into the previous step):
    "C:\OneDrive\Apps\Putty\pageant.exe" %userprofile%\.ssh\mykey.ppk
  8. Now you just need to add the public key to the services you want to use it with, and you should be good to go.

One thought on “Setting up SSH for Git on Windows

  1. Thank you Gus – this guide will come in handy when I’m setting up my connection to BitBucket on a new workstation.

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.