Key-Based SSH Logins With PuTTY - Page 4

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Wed, 2006-12-06 23:04. ::

9 Disable Username/Password Logins

Up to now, you can log in with your private/public key pair and still with username/password logins, so if someone doesn't attach a private key to his PuTTY session, he will be asked for a username and password. So to achieve a better security, we must disable the username/password logins (you should do this only when you know that your key-based logins are working, because if they aren't and you disable username/password logins, then you have a problem...).

To disable the username/password logins, we must modify the sshd configuration file. On Debian/Ubuntu systems, it's /etc/ssh/sshd_config. You should set Protocol to 2 (1 is insecure and should not be used!), PasswordAuthentication to no, and UsePAM to no (or comment out the UsePAM line), e.g. like this:

vi /etc/ssh/sshd_config

[...]
Protocol 2
PasswordAuthentication no
UsePAM no
[...]

Then restart sshd. On Debian/Ubuntu, you can do it like this:

/etc/init.d/ssh restart

Now if you open a PuTTY session without your private key attached, you shouldn't be able to log in anymore.

 

10 Let Pageant Remember Your Key Passphrase

Whenever you use your key-based login now, you stilll have to specify your key passphrase. This can be annoying if you connect to the SSH server multiple times a day. Fortunately, you can tell the passphrase to Pageant which will then provide the passphrase whenever you log in to your SSH server.

You can start Pageant by double-clicking its executable file:

Afterwards, you should see running Pageant in the taskbar:

Now double-click the Pageant icon in the taskbar. The following window comes up. Click on Add Key:

Browse your filesystem and select your private key:

Then enter the passphrase for the private key:

The key is now listed in Pageant's key list. Click on Close:

As long as Pageant is running in the taskbar, you can log in to your SSH server without providing the passphrase - this is done by Pageant:

When you stop Pageant, it forgets all keys, so the next time you start Pageant you must add the keys again. This can also be annoying, but to prevent this, we can create a shortcut on the desktop to the Pageant executable. Right-click the Pageant executable and select Create Shortcut:

You should now find a shortcut. Right-click it and go to Properties:

Under Target, you will now find the path to pageant.exe, e.g. "C:\Dokumente und Einstellungen\falko\Desktop\pageant.exe" (if there are no spaces in your path, you don't need the quotation marks). You can now simply add the location of your private key to that line, for example if you private key is C:\putty\my_keys\private_key_192.168.0.100.ppk then the line should look like this:

"C:\Dokumente und Einstellungen\falko\Desktop\pageant.exe" C:\putty\my_keys\private_key_192.168.0.100.ppk

(if there are spaces in the path to your private key, you must wrap it in quotation marks again, e.g. like this:

"C:\Dokumente und Einstellungen\falko\Desktop\pageant.exe" "C:\directory with lots of spaces in name\my keys\private_key_192.168.0.100.ppk"

)

Then click on OK:

Now when you double-click on the Pageant shortcut, Pageant will automatically load your private key and ask you for the passphrase. Enter it, and that's it.

 

11 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by David Coll (not registered) on Mon, 2013-04-22 04:58.

Doing this will result in most frequent Server resused your key.

 You must create your private key on linux using "ssh-keygen", then import the private key in putty, save it on window for putty-use.

On server you do "cat id_rsa.pub >> authorized_keys2  "

 ..and voila.

Submitted by krumov (not registered) on Wed, 2013-01-23 16:05.

This is really Good HowTo which is clear enough for everyone , even the newest people who are touching the mouse and the keyboard for the first time ever.

Great !

Submitted by Fredy10 (not registered) on Thu, 2013-01-03 17:46.

Very good how to! its very easy and clear!

Thanks!

Submitted by Anonymous (not registered) on Tue, 2012-07-03 18:11.
Drove me nuts - Listening on the wrong port in sshd_config, changed it because work think it is a safer to use the known port...
Submitted by DreadfullyDespized (not registered) on Wed, 2012-03-07 04:58.
This is a great article, thanks for this.  It worked great on my WD My Book Live 2TB.
Submitted by Anonymous (not registered) on Wed, 2012-02-22 17:15.
Thanks for this great tutorial! 
Submitted by KB (not registered) on Sat, 2011-12-10 20:31.

Very well done and easy to follow directions.

I had problems with the keys generated by putty for some unknown reason, possibly due to not adding the username, though I'm not sure.

Instead, I generated them on the server using ssh-keygen -t rsa then copied the .pub key over to authorized_keys2 and downloaded the private key to my local machine (being sure to remove the private key from the server for security purposes afterward). I then was able to import the private key into PuttyGen and save it out as a .ppk file and work with the rest of your instructions.

Submitted by uptoome (not registered) on Tue, 2011-09-13 17:31.
This worked right out of the box. Thank you.
Submitted by Michael (not registered) on Wed, 2011-08-10 12:17.

Very clear and simple, thanks.

Submitted by metazone (not registered) on Tue, 2011-06-07 16:48.
This should be a model for tutorials -- succinctly states why we need to do something and then provides a very nice explanation --
Submitted by Angel S. Moreno (not registered) on Wed, 2011-05-18 04:23.
I've been using putty for a while but never made use of the tools or settings described. Super helpful.
Submitted by Mike G. (not registered) on Wed, 2011-05-04 17:54.

Excellent tutorial -- it was very clear and well written.

Submitted by TeHZomB (not registered) on Fri, 2011-01-28 05:57.
Thanks, this guide is great and really easy to follow! Even five years later, works like a charm.
Submitted by Thiago Cruz (not registered) on Tue, 2010-07-27 15:31.
Excelent step-by-step. I used it with plink. Thanks
Submitted by Neil (not registered) on Wed, 2010-07-21 08:37.

Thank you so much. Easy, step by step, and it just works.

 Wonderful.

Submitted by Mikeomillian (not registered) on Sat, 2010-03-20 15:49.
I was actually trying to admin my VPS without command line, because I had tried putty once and it didn't work. This got it working in about 10 minutes, thank you!
Submitted by Damian (not registered) on Mon, 2009-12-14 16:17.
Just been pulling my hair out trying to get Windows to talk nicely to Ubuntu and this nailed it. Cheers Damian
Submitted by Anonymous (not registered) on Sat, 2009-11-07 06:01.

Thanks for this.

 This is a great site with lots of useful stuff explained in a clear and concise manner.

Submitted by Matt_Yun (registered user) on Sun, 2006-12-10 20:23.
There is a version of PuTTY called PortaPuTTY that can be installed to USB drives, without any Registry modifications.
Submitted by Daniel15 (registered user) on Fri, 2006-12-08 10:11.
I've always wanted to do this, but have never known how. This tutorial told me exactly what I needed to know. Thanks!