SSH and Git on Windows (with Public\Private Key Authentication)

This Blog Post consists in huge parts of Daniel Hüskens awesome work, but I still had to rewrite it a bit as I tended to add some stuff on :).

1.) Download latest Git for Windows: https://git-for-windows.github.io/

2.) Install (Entires with * can be changed to your own liking, ** can be changed, but this setting is recommended)

  • "Without Windows Explorer Integration" *
  • "Run Git and included Unix tools from Windows Command Prompt"
  • "Use OpenSSH"
  • "Checkout Windows-style, commit Unix-style endings" **
  • "Use Windows default console window" **

3.) Configure

  • set set HOME=%HOMEDRIVE%%HOMEPATH% in your Windows User Path Variables: Press WIN+X Key, choose System, Advanced Systemsettings, Advanced, Path Variables - or just press WIN+R and enter "C:\Windows\system32\rundll32.exe" sysdm.cpl,EditEnvironmentVariables- you will need to click on New, then create a new Variable HOME  with the Value %HOMEDRIVE%%HOMEPATH%, click ok and close everything.
  • create the Folder .ssh in your User Folder (C:\Users\YourName\)
  • if you want to store your ssh Config and Credentials somewhere else, you need to use a symlink. Start your CMD in Administrator Mode (Press Windows Key, type cmd, rightclick on the found program, start as Administrator) and create the link with mklink /D "C:\Users\YourName\.ssh" "D:\mySecretFolder\.ssh" The path D:\mySecretFolder\.ssh does have to exist before this action, .ssh in the YourName folder not :).

4.) Create a key and test access to Github

  • Go to your .ssh folder and open a CMD there
  • ssh-keygen -t rsa -C "a good comment on what this key is for" -b 4096
  • Your key has been created, it should be named id_rsa and id_rsa.pub. The content of id_rsa.pub can be added as new ssh key to your Github profile on: https://github.com/settings/keys
  • After that you can test your setup with ssh -T git@github.com
  • If anything goes wrong, add verbosity to your SSH command, i.e. with -vvv (more v's equals more debug messages)

5.) Word of advice:

SSH can be a bit tricky, as it tends to only look for id_rsa named keys in your .ssh folder. So if you have multiple keys with different names chances are high that this won't work. However, you can get around that with entries in the user defined ssh config file (called "config" and placed in the .ssh folder of the user) to tell ssh which key to use with which ssh connection. I will add a post on that topic later and link it here.
EDIT: Here is the link

Leave a Reply

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