How To Configure SSH Keys Authentication With PuTTY And Linux Server In 5 Quick Steps

Want to support HowtoForge? Become a subscriber!
 
Submitted by EugenePik (Contact Author) (Forums) on Fri, 2009-06-26 15:38. :: Linux | Security

How To Configure SSH Keys Authentication With PuTTY And Linux Server In 5 Quick Steps

This tutorial explains how you can replace password-based SSH authentication with key-based authentication which is more secure because only the people that own the key can log in. In this example, we're using PuTTY as our SSH client on a Windows system.

 

1. Get the zip file with all PuTTY binaries

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

2. Generate a private and public key pair

Open PuTTYgen.exe, press Generate button, move mouse. Once the keys are generated, type your key passphrase (choose a "hard to guess" one). Save Public key. Save Private key.

Screen shot: PuTTY key generator

3. Configure your Linux server (create user, save public key)

For this guide let's assume you regular login name is autotimesheet (replace it with one that you use regularly).

As root, on the shell, type:

adduser autotimesheet --disabled-password

You will be asked to fill in some details such as the user's real name (empty string is fine).

Now type:

su autotimesheet
cd /home/autotimesheet
mkdir .ssh
chmod 700 .ssh
cd .ssh

Then in that folder, create and edit a file called authorized_keys2.

In there, cut/paste your public ssh key, on ONE LINE (That is very important!!!)

Do not add the email@example.com at the end of the line.
Do not add the BEGIN PUBLIC KEY or END PUBLIC KEY.
Do not add the rsa-key-20090614 at the end.
Make sure, there is ssh-rsa at the beginning.

It should be something like:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBzPeFQv+295iKzuuPH0jA9449pSHVpCwXvCR9EstmYh...

Type:

chmod 600 authorized_keys2

 

4. Add Private key to PuTTY SSH authentication agent

Start the PuTTY SSH authentication agent PAGEANT.EXE. When started, right-click its syspanel icon...

Screen shot: Pageant - syspanel icon

... and select "add key". Select your private key file, and type in your passphrase when you add the key. The Pageant works as a passphrase keeper.

 

5. Use PuTTY to connect to your server

Open PuTTY and connect as autotimesheet@yourserver:

Screen shot: PuTTY - connect to a server

See that you log in without a password ...

Screen shot: PuTTY - Authenticating with public key from agent


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 Nick (not registered) on Sat, 2009-07-04 10:35.

The authorized_keys2 file has been deprecated since the OpenSSH 3.0 release (2001).
See
http://marc.info/?l=openssh-unix-dev&m=100508718416162&w=2

Submitted by wese (not registered) on Fri, 2009-06-26 16:18.

I believe you didn't set the owner right.

chown -R autotimesheet. /home/autotimesheet/.ssh

Submitted by Suno Ano (not registered) on Fri, 2009-06-26 15:52.

Hi folks,

I wrote an article about PKA as well

http://sunoano.name/ws/public_xhtml/ssh.html#public_key_authentication

 Maybe someone might find it useful ...

Submitted by Anonymous (not registered) on Sun, 2009-06-28 15:24.

http://www.ssh-key-authentication.com/

 i wrote anything you need to know and more at that site

plus : you get an automatic script.

 

enjoy

Submitted by Suno Ano (not registered) on Mon, 2009-06-29 20:42.

Hi there ... 

Hints:

Your howto advices people to use scp to transfer the public key to the remote machine. This often causes permission problems. The prefered way is to use ssh-copy-id as shown here

http://sunoano.name//ws/public_xhtml/ssh.html#transferring_the_public_key_to_the_remote_machine

Also, just to stress the fact again, a keypair should always be protected by a passphrase i.e. "leaving empty for no password" should not be done:

http://sunoano.name//ws/public_xhtml/ssh.html#why_does_public_key_authentication_benefit_me

 

Monkeysphere:

Personally, I am now using Monkeysphere on top of PKA all the time now because it also solves the problem how to authenticate servers and users:

http://sunoano.name//ws/public_xhtml/ssh.html#monkeysphere

Submitted by dhanesh mane (not registered) on Mon, 2011-01-17 08:55.

perfect article. Works perfect and steps are really explained properly. Only thing is I am using ubuntu so at 3rd step I used sudo su -l autotimesheet command instead of su autotimesheet

Thanks a lot for such a nice article.