Windows - Using GPG for SSH authentication (and Git)
Windows can use GPG for SSH auth just like Linux, although the configuration is a bit different. You can even use your same GPG smartcard so private keys don't need to be sitting around on your disk.
Install & Setup Gpg4win
Only the command line tools need to be installed. I'm not going to cover setting up keys as it's identical to Linux.
For smartcard usage just importing your public key and setting the trust level is needed. Windows should automatically install drivers for a smartcard when it's plugged in.
Setup gpg-connect-agent
When logging in, gpg-connect-agent /bye
needs to be called. There are a lot of ways to do this. Here's the PowerShell scheduled job I use:
Install PuTTY
PuTTY
is used as a replacement for OpenSSH since it works with Gpg4win
via Pageant.
Once installed, authenticating with remote hosts from PuTTY
should work, and it should prompt for a smartcard PIN if needed.
Enable PuTTY
support in GPG
Add the following line to %APPDATA%\gnupg\gpg-agent.conf
:
Configuring Git
to use Gpg4win
and PuTTY
Add an environment variable to direct Git
to use plink
instead of the builtin OpenSSH
:
Git
on Windows uses its own bundled GPG, so direct it to use Gpg4win
in .gitconfig
:
Usage
Everything should now 'just work' for push/pull/signing in Git
. One caveat with Git
is that when a server fingerprint isn't recognized it cannot be added to known hosts via the command line as input isn't recognized. The workaround for this is to first connect via PuTTY
.