On an otherwise pristine Windows 7 Enterprise install:
- Install PuTTY 0.62
- Create public/private key pair with puttygen.exe
- Add public key for pasting into OpenSSH authorized_keys to github account
- Add private key to pageant
- Install msysgit 1.7.8 with the following options:
- Use Git from Windows Command Prompt
- Use (Tortoise)Plink pointed to correct plink.exe
- Make sure github fingerprint is added to know_hosts by connecting to github.com in PuTTY and accepting fingerprint
-
Edit
~/.ssh/config
to read:Host github.com User git Hostname github.com PreferredAuthentications publickey IdentityFile ~\.ssh\github.ppk
ssh -vvvT git@github.com
gives: http://pastebin.com/Tu3Fc6nJ. Note that I'm being prompted for the pass-phrase despite it being successfully loaded into pageant.
I've tried: chmod 700 ~/.ssh; chmod 600 ~/.ssh/*
from within Git Bash but there was no effect as verified by ls -l
.
I should note that I had this exact setup working on a previous Windows 7 install. Everything is identical as far as I can tell.
What does work is generating keys from within Git Bash. However, I cannot add those keys into pageant, which is a huge pain. In effect, it seems that any attempt to use keys generated by PuTTY is unsucessful.
Any insight on what's preventing this from working based on the logs? Thanks in advance.
Best Answer
I have put together a step-by-step guide to get Git setup for windows using PuTTY's Plink application for SSH authentication.
Follow along below:
Setup
Install putty.zip which is available at the PuTTY Download Page or you can download individually.
PuTTY: putty.exe (or by FTP)
The SSH and Telnet client itself.
Plink: plink.exe (or by FTP)
A command-line interface to the PuTTY back ends.
Pageant: pageant.exe (or by FTP)
An SSH authentication agent for PuTTY, PSCP, PSFTP, and Plink.
PuTTYgen: puttygen.exe (or by FTP)
An RSA and DSA key generation utility.
Generate RSA and PPK Keys
ssh-keygen
to generate a pair of RSA public/private keys. More information on how to do this can be found on the official Generating SSH keys article.~/.ssh/id_rsa
(private) key, via Conversions → Import key.~/.ssh/id_rsa.ppk
.You should now have the following keys in your
~/.ssh
directory:id_rsa
: Private (OpenSSH) RSA keyid_rsa.pub
: Public (OpenSSH) RSA keyid_rsa.ppk
: Private (PuTTY) keyInstall Git for Windows.
Make sure that you choose to use Plink.
Note: If you have already installed Git, you can just run the installer again and set Plink to be your default SSH application.
Set your Environment paths.
Add the following System variables (if not already set):
GIT_HOME
:C:\Program Files\Git
GIT_SSH
:C:\Program Files (x86)\PuTTY\plink.exe
Append the Git binary directory to the system path.
Path
:%Path%;%GIT_HOME%\bin
Open Pageant and load the ppk key located at
~/.ssh/id_rsa.ppk
.Note: Once Pageant has started, you can click on its icon in the system tray located in the taskbar, next to the time, on the right.
Open Putty and connect to test your connection via SSH and add the server's key as a known host.
Examples hostnames:
git@github.com:22
(or via ssh-agentssh -Tv git@github.com
)git@bitbucket.org:22
(or via ssh-agentssh -Tv git@bitbucket.org
)Start Git Bash.
You should be able to push and pull from your remote host without entering a password each time.
Shortcut
You can place a shortcut in your startup directory to auto-load your key each time you log into your Windows account.
Via Batch Script
This idea was inspired by an answer to this question:
Via Windows Explorer
Navigate to the startup directory in Windows Explorer.
User
Startup/
directory (preferred) is located at:All Users
Startup/
directory is located at:Right-click inside the folder and select New → Shortcut
In the Create Shortcut dialog, enter the following information.
"C:\Program Files (x86)\PuTTY\pageant.exe"
Pageant Autoload
Right-click the new shortcut and choose Properties from the context menu.
Modify the following fields under the Shortcut tab:
"%PROGRAMFILES(x86)%\PuTTY\pageant.exe" id_rsa.ppk
%USERPROFILE%\.ssh
Notes:
If you are using a 32-bit Windows OS, you should use the
%PROGRAMFILES%
environment variable instead of%PROGRAMFILES(x86)%
.If you placed your shortcut in the All Users startup directory, make sure that the current user has an
id_rsa.ppk
key in their~/.ssh
directory or the key will not auto-load.Closing Remarks
There you have it. Next time you log into your Windows profile, you will be greeted with a Pageant prompt to enter the password for your key. If you did not set a password on your key, then your key should be loaded automatically without a prompt.
If you are not sure if your key loaded view the current keys in Pageant by selecting View Keys from the context menu for Pageant in the system tray.