1. Download the putty and puttygen utilities from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. I like to place these executables under my c:\Windows\system32 directory, so that they are available in the command prompt without additional PATH configuration.
2. Start puttygen and generate a new keypair. I prefer to use SSH2-RSA 4096 bit key. Click the generate button and move your mouse around to generate some randomness. Save the private key; you will use it when configuring putty to connect to your Ubuntu box.
3. Copy the public key from the textbox titled "Public key for pasting into OpenSSH authorized_keys file.
4. Start putty and connect to your Ubuntu box using a username and password.
5. On the Ubuntu box, create the .ssh directory under your home directory:
mkdir ~/.ssh
6. Set the correct permissions:
chmod 700 ~/.ssh
7. Create the authorized_keys file:
nano ~/.ssh/authorized_keys
8. Paste the public key (the one generated by puttygen), save the file (Ctrl+O), and exit (Ctrl-X).
9. Set the correct permissions for the authorized_keys file:
chmod 600 ~/.ssh/authorized_keys
10. Verify that OpenSSH is configured to look for authorized_keys file in the home directory; sometimes, it is defaulted to look for authorized_keys2, etc. To verify OpenSSH service configuration, you need the sudo access:
sudo nano /etc/ssh/sshd_config
11. Look for the line AuthorizedKeysFile %h/.ssh/authorized_keys; it is usually commented out, so un-comment it. Save the configuration file (Ctrl-O), and exit (Ctrl+X). FYI - %h expands to mean the user's home directory.
12. Restart OpenSSH service:
sudo service ssh restart
13. Back on the Windows machine, configure putty to use the private key generated in step 2. Start putty and change the following settings:
* Under Session, enter the hostname as [yourusername]@[yourubuntuhostname], e.g. user1@server1.
* Under Connection->SSH->Auth->Private Key for Authentication, browse to select the private key file you generated in Step 2.
* Customize appearance under Window (columns, rows, number of lines to scrollback); this is optional.
* Under Session->Saved Sessions, give a session name and click the Save button.
14. Now from the command prompt, you can start putty with a session name to automatically login to your Ubuntu box with the private key authentication option:
putty -load [yoursessionname].
15. Create a small bat/cmd file "ssh-to-myserver.cmd" and paste the following inside:
@echo off
putty -load [yoursessionname]
Now you can just double-click on the cmd file, and it will launch putty.
16. In order to convert puttygen private key into the openssh private key, load the private key into puttgen and use the Conversion->Export as OpenSSH option to save the ssh id file. Then you can use this file as the IdentityFile option in your ssh configuration.
Troubleshooting:
If your Ubuntu server continues to ask you for a password, you can try to run the OpenSSH service in the debug mode, which produces a lot of output and can help pinpoint a problem:
1. Stop the OpenSSH service on your Ubuntu box:
sudo service ssh stop
2. Start the OpenSSH service in the debug mode (it will log the (verbose) output to the console:
/usr/sbin/sshd -d
3. Attempt to connect again with a private key (using putty) and watch the output in the Ubuntu console for any error messages.