Archive for June 2012

Video tutorial: Setting up SSH public key authentication in Ubuntu 12.04

I’ve been using Linux for quite some time now but never really understood how public key authentication works. I decided to search the web and try it out on different testing machines. So, if you want to find out how it works as well, here’s how it’s done.

 

 

 

 

 

 

First, you’ll need to log in to your machine, and create a necessary directory, change it’s permissions and go into it.

$ mkdir .ssh/; chmod 700 .ssh/; cd .ssh/

After that, you want to create a file called ‘authorized_keys’. This file contains the public key(s) that are allowed to log-in with your username.

$ touch authorized_keys; chmod 600 authorized_keys

Right now, it should look like this:

$ ls -lh

-rw——- 1 kevin kevin  394 Jun  3 13:00 authorized_keys

It’s time to generate the public/private rsa key pair:

$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/kevin/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kevin/.ssh/id_rsa.
Your public key has been saved in /home/kevin/.ssh/id_rsa.pub.

Your .ssh/ directory should look like this right now:

ls -lh

-rw——- 1 kevin kevin 394 Jun 3 13:00 authorized_keys
-rw——- 1 kevin kevin 1.8K Jun 3 14:16 id_rsa
-rw-r–r– 1 kevin kevin 394 Jun 3 14:16 id_rsa.pub

Add the id_rsa.pub key to the authorized_key file

cat id_rsa.pub >> authorized_keys

Next, download the private key (id_rsa) file to your local Windows machine by using WinSCP.

Open PuTTYgen, click ‘load’ and search for the id_rsa file you just downloaded from your Linux machine. Enter your passphrase and hit OK. Now, click ‘Save private key’ and select a good destination to store your private key file.
At last, open PuTTy, enter the IP address or hostname of your Linux machine and go to Connection -> SSH -> Auth.

 

At the bottom you will find ‘Private key file for authentication:’. Hit browse, and select the key file we just saved with PuTTYgen. Hit open, enter your username, your passphrase and ta-da.

 

 

references:

http://en.wikipedia.org/wiki/Secure_Shell

http://andremolnar.com/how_to_set_up_ssh_keys_with_putty_and_not_get_server_refused_our_key

http://www.ubuntu.com/

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html