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

Configure Git Line Endings

I tend to work crossplatform on different systems, mostly switching between different kinds of Ubuntu/Debian and Windows machines - always checking out and commiting git files on those machines. And I always forget to get the Git Line Endings right, as soon as I add a new machine to that list... So to do that, just a quick one liner:

git config --global core.autocrlf input
# Configure Git on Linux to properly handle line endings

 

Gitkraken - your next Git Client

If you're in the NetOps/DevOps Teams, chances are high you need to develop code and use git. Well, on Windows Clients, I tended to use Atlassians Source Tree - however, that client became more and more buggy and unstable - unusable to say. Especially if I had to do an really big merge of my main to my deploy tag - it tended to crash most of the time.

So, without further ado: Enter Gitkraken. A nice, free, good looking and fast git client. Without dependencies.

Only downsides: It uses Electron - so it is basically a packaged Node JS server. It is - quite fast, however - and it does not need to install any other dependencies. The other "downside" is, if you want to use more than one GitHub Account, you need to pay for these kind of features.

However, as long as there is no "real" alternative to this product, I will remain using it :).