Generating and Using an SSH Key on a Microsoft Windows MachineThe three sections that follow describe how to generate an SSH key with the free program PuTTY, how to copy the key to the SSH Keys tab in your user profile settings, and how to manage your client keys with Pageant and Plink.
Note: If you plan to use your public key with Git, you can use Git Bash to generate and test the key. GitHub has great help pages on this. For the Windows page, see http://help.github.com/msysgit-key-setup/.
Thanks to Oliver Reeves (OJ) for his blog Setting up Trac, Mercurial, and SSH on Windows, which was very helpful in writing this page.
You can use the free program PuTTY to create an SSH key. To manage and access the key, you'll probably want to download Pageant and Plink as well. You can get them all at PuTTY Download Page.
After installing PuTTY, make sure the install path has been added to your PATH environment variable.
PuTTY comes with excellent documentation on what SSH is and how to generate a key with PuTTYgen. Here are some short instructions:
- Start PuTTYgen by clicking Start > All Programs > PuTTY > PuTTYgen.
- At the bottom of the window, click SSH-2 RSA to generate the most secure kind of key. Project Kenai requires an SSH-2 key.
- Click Generate and move the mouse around until the key starts generating.
- When the key is generated, you see the public key listed in the Public Key for Pasting box at the top of the window.
- Optionally enter a passphrase for the key, which makes it more secure on your machine.
- Click Save public key and save it in a file in your user directory. For example, you might save it in
C:\Documents and Settings\your-user-name\.ssh\puttypublickey-ssh2rsa
Note: You can use the Command window to see what your user directory is. On the command line, enter echo %USERPROFILE%.
- Click Save private key to save the private key to a file in the same directory as your public key. For example, you might save it in
C:\Documents and Settings\your-user-name\.ssh\puttyprivatekey-ssh2rsa.ppk
- Keep PuTTYgen open so you can copy and paste your public key to your Project Kenai account. (See next section.)
The public key that you see in the Public Key for Pasting box in PuTTYgen needs to be added to your SSH Keys tab in your Project Kenai public profile. To add the key:
- In a browser, log in to Project Kenai.
- If necessary, open your My Page.
- Click Edit My Profile in the left navbar.
- On the My Profile edit page, click the SSH Keys tab.
- Copy the public key from PuTTYgen and then follow the instructions at Adding an SSH Key to Your Profile.
When using SSH, you'll have to have to specify the passphrase each time you connect to the server, which can get annoying quickly, especially if you do a lot of commits. Instead of typing your passphrase every time, you can use the Pageant utility that comes with PuTTY. Pageant starts up once, stays in memory, and handles access to the private key for you.
Note: Plink is the command line interface to Pageant, so if you have Pageant running, version control software like Mercurial that can use Plink can also access your key.
To set up Pageant with your key:
- Start Pageant by clicking Start > All Programs > PuTTY > Pageant.
- Click “Add key” and browse to the folder where you stored your .ppk file, then select the file.
- When prompted, specify your passphrase and click OK.
- The key fingerprint of the private key appears in the list box. Pageant is now in memory and handling that key.
- Close Pageant. You'll see it still running in the system tray.
Hint: Add the Pageant shortcut to your startup folder so it runs whenever you log in to your machine.