Skip to content

Instantly share code, notes, and snippets.

@jbrown123
Last active November 4, 2024 14:33
Show Gist options
  • Save jbrown123/16ede76b87aab1491c6b1dc809a4e03c to your computer and use it in GitHub Desktop.
Save jbrown123/16ede76b87aab1491c6b1dc809a4e03c to your computer and use it in GitHub Desktop.
How to use PuTTY with github on Windows

How to use PuTTY with github on Windows

To make things easier, we can tell git to use the PuTTY tools rather than the built in ssh client. The PuTTY tools include an identity manager and an SSH replacement.

Follow these four steps:

  1. Download and install PuTTY using the MSI installer package from the PuTTY download page. Alternately, you can just get the "PLink" and "Pageant" executables from the same page and save them somewhere in your path.

  2. Add a new user or system environment variable:

  • Press Windows+R and enter sysdm.cpl
  • Select the 'Advanced' tab
  • Press the 'Environment Variables' button at the bottom of the window
  • In the new dialog that appears create a new user or system environment variable named GIT_SSH
  • Set the value to the full path for plink.exe, for example C:\Program Files\PuTTY\plink.EXE

Open a new command prompt for the following steps. This needs to be a new command prompt, after you added the environment variable, so the GIT_SSH value is set.

  1. Run pageant your_key.ppk (replace 'your_key.ppk' with the path and name of your PuTTY key file). If your key is password protected, pageant will ask you to enter your password.

  2. PuTTY / plink needs to verify the host before it lets you attach to it. Unfortunately git doesn't pass the keyboard input back to plink so you'll need to do a one-time connection to github.com in order to get plink to add the fingerprint to the known_hosts file.

This is a one-time configuration. You wont need to do this again on the same machine unless github.com changes their server fingerprint (unlikely, but possible).

Run plink [email protected] and wait for the fingerprint prompt

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) 

Press 'y' in response to this prompt and plink will continue with

Using username "git".
Access granted. Press Return to begin session.

Press enter at this prompt and plink will respond with

Server refused to allocate pty
Hi [your username]! You've successfully authenticated, but GitHub does not provide shell access.

You can now use git like you would on any other operating system. Commands like git clone, git pull, git push, git branch -a, etc. that access the upstream repository will now work correctly.

Be sure it says 'Clone with SSH or select the 'Use SSH' option in github when cloning a repo. PuTTY / plink / pageant can't help you with an https cloned repo.

@jbrown123
Copy link
Author

jbrown123 commented Jan 29, 2023

@GabauxHu,

You NEVER share your private keys with ANYONE. That's why it's called the "private" key.

The "public" key is the one you share with the PUBLIC.

Consequently, push the PUBLIC key to github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment