Key-Based SSH Logins With PuTTY

This guide describes how to generate and use a private/public key pair to log in to a remote system with SSH using PuTTY. PuTTY is an SSH client that is available for Windows and Linux (although it is more common on Windows systems). Using key-based SSH logins, you can disable the normal username/password login procedure which means that only people with a valid private/public key pair can log in. That way, there is no way for brute-force attacks to be successful, so your system is more secure.

 

1 Preliminary Note

In this tutorial I use a Windows desktop to connect to a Linux SSH server (Debian with IP address: 192.168.0.100).

 

2 Install PuTTY, PuTTYgen, And Pageant On The Windows System

First we need to install PuTTY, PuTTYgen, and Pageant on our Windows system. All we need to do is download the exectuable files (.exe) and save them somewhere, e.g. on the desktop. We don't need to install them as they are standalone applications. To start them, we only need to double-click them.

Download the following files from the PuTTY download page and save them on your Windows system, e.g. on the desktop:

http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe

http://the.earth.li/~sgtatham/putty/latest/x86/pageant.exe

 

3 Create A Profile With Settings For Our 192.168.0.100 Server

In PuTTY, you can create profiles for connections to your various SSH servers, so you don't have to type in the settings again when you want to connect to a certain server again.

Let's create a profile for our 192.168.0.100 server. Start PuTTY by double-clicking its executable file. You are now in the category Session (see the tree on the left side of the screenshot). Enter 192.168.0.100 under Host Name (or IP address), enter 22 under Port and select SSH under Protocol:

Then go to Connection -> Data and specify the username with that you want to log in to your SSH server under Auto-login username. In this article I use root:

Then go to Session again. Under Saved Sessions enter a name for the profile, e.g. 192.168.0.100 or any other string that lets you remember for which server the profile is. Then click on Save:

The next time you use PuTTY, you can simply select the appropriate profile from the Saved Sessions textarea, click on Load and then Open.

Share this page:

11 Comment(s)

Add comment

Comments

From: FalconsMaze at: 2010-06-19 18:43:49

Thank you for the detailed screen shots and hand holding.  I was able to set this up in five minutes.  On other blogs there are a lot of steps omitted or :"your just suppose to know that setup."

Awesome job!

 

From: dcb at: 2012-08-16 09:13:49

This is well explained thank you. Putty does it's job well, but there are few instructions around that explain how to use it. The messages from failed login attempts rarely give any clues about how PuTTY should be set up. Many thanks for taking the time to document these settings and explain them so clearly. It is much appreciated.

David.

From: DizzyBum at: 2013-02-25 16:18:57

Thanks for this article!  I use Putty non-stop at work and this is going to cut out a lot of the time I spend copying and pasting long passwords.  Very clear and simple instructions.

From: Brian at: 2013-07-23 18:58:13

Thanks for explaining the whole process! I had stumbled through the key generation but couldn't figure out how to get the public key to the server in the right spot. I've bookmarked this page for future reference, because at my new job I've got a lot of servers to ssh to.

From: thatsimonguy at: 2015-04-21 15:36:48

This post really helped me and I was able to successfully setup a private/public keypair between my Win7 machine and my Ubuntu box for login.  Thanks.

From: alex_rsku at: 2015-05-07 21:30:41

What if I want to create few pub keys? Should I append these keystrings to authorized_keys2 , what separators are ?

From: M. Gy. at: 2015-05-18 09:09:07

Authorized keys are checked in both ~/.ssh/authorized_keys and authorized_keys2 by default. openSUSE (and maybe other) distros do not use authorized_keys2, so if you cannot login with your brand nem key pair, try to rename the file to authorized_keys.

Rgrds - M. Gy.

From: M. Gy. at: 2015-05-18 09:13:31

Switching off PAM (usePAM no) in /etc/ssh/sshd_config has some side effects. It is safer to write:

ChallengeResponseAuthentication no

instead. It still disables keyboard-interactive login, but leaves PAM to be used.

From: M. Gy. at: 2015-05-18 09:15:52

A 2048 bits long key can be used, it is safer and it is now the default in PuTTYGEN.

From: abhishek at: 2015-07-28 14:26:21

thank you.

From: Markus at: 2015-08-11 09:24:43

Thanks!!!