Skip to content

Instantly share code, notes, and snippets.

Last active July 18, 2024 16:59
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 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 changes their server fingerprint (unlikely, but possible).

Run plink 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
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.

Copy link


Copy link

You're welcome. I'm glad it helped someone.

Copy link

Subbaram1993 commented May 19, 2022


I was trying with the following procedure to install and connect my Git with putty, while executing the command plink its giving the error below
git error

Can you please suggest how to install the git with putty in my pc or any steps are missing.

Copy link

It appears that you do not have your key loaded in memory. You MUST load your key in memory via the pageant command (see step 3).

The other possibility is that you don't have a key registered with github.

Copy link

Run plink and wait for the fingerprint prompt

Actually this step can be automated (e,g. in a Windows batch script) by doing:

rem Contact the server and feed a 'y' to accept fingerprint
rem (ignore 'stdout' and 'stderr' as we're only interested in the acceptance action)
echo y | plink>nul 2>&1

rem Check if the server is recognized by Putty by checking the registry entry added by plink
rem (ignore 'stdout' as we're only interested in the result/errorlevel set by find)
reg query "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys" | find "">nul
if errorlevel 1 (
  echo   Error: could not add new server^!
) else (
  echo   Success: the server should now be recognized by Putty.

Sample output just to illustrate the goal. 😊

Copy link

ghost commented Nov 23, 2022

Thanks for the info.

Copy link

I'm glad you found it useful!

Copy link

Hi I have created keys with Puttygen on wihdows, and saved both the public and private keys. Which should I add to GitHub? Thanks in advance.

Copy link

jbrown123 commented Jan 29, 2023


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