Thursday, November 24, 2011

How to Setup Password-less SSH Using Public - Private Keys

This HOWTO is a step-by-step guide for configuring and using password-less SSH service on Linux systems and is intended for a technical audience only.

The term “password-less” means that SSH authentication is carried out by using public and private keys. Using public/private key authentication with SSH enables SSH logins without requiring passwords interactively and this is known as SSH key authentication.

You need to generate a pair of public/private keys on your client system. In order to generate public/private keys on your client system use the ssh-keygen program within a terminal as shown below.

[shihora@linuxhungrymind ~]$ ssh-keygen -t dsaGenerating public/private dsa key pair.
Enter file in which to save the key (/home/shihora/.ssh/id_dsa):
Created directory '/home/shihora/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/shihora/.ssh/id_dsa.
Your public key has been saved in /home/shihora/.ssh/id_dsa.pub.
The key fingerprint is:
D2:0e: ad: 54:e7:c2: 2e: 51:cb: cd: 7b: 68:db: 19:d3: 6e
shihora@linuxhungrymind

After you have created the public/private key pairs on your client machine, you need to copy the newly created public key to the server.

scp ~shihora/.ssh/id_dsa.pub  username@AnotherLinuxHungryMindServer:~username/.ssh/authorized_keys2

cat id_dsa.pub >> authorized_keys2

Certainly, you don’t want normal system users to alter the server’s authorized_keys2 file.

$ chmod 600 authorized_keys

After performing these operations you are done! Your server is ready to accept SSH connections from your client without requesting a password.

No comments:

Post a Comment