SSH login without password


SSH login without password or Keybased Authentication 

password less ssh 

Problem : SSH login without password 

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login

from host A(amitmaheshwari.in) user "tom"  --> to Host B (xyz.com)  user "jim".

You don't want to enter any passwords, because you want to call ssh from a within a shell script.

Solution : How to do it

First log in on A as user tom and generate a pair of authentication keys. Do not enter a passphrase:

tom@amitmaheshwari.in:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_rsa):
Created directory '/home/tom/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tom/.ssh/id_rsa.
Your public key has been saved in /home/tom/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:38:e4 tom@amitmaheshwari.in

Now use ssh to create a directory ~/.ssh as user jim on xyz.com. (The directory may already exist, which is fine):

tom@amitmaheshwari.in:~> ssh jim@xyz.com mkdir -p .ssh
jim@xyz.com's password:

Finally append tom's new public key to jim@xyz.com:.ssh/authorized_keys and enter jim's password one last time:

tom@amitmaheshwari.in:~> cat .ssh/id_rsa.pub | ssh jim@xyz.com 'cat >> .ssh/authorized_keys'
jim@xyz.com's password:

From now on you can log into B as jim from A as a without password:

tom@amitmaheshwari.in:~> ssh jim@xyz.com
jim@xyz.com:~>

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:
Put the public key in .ssh/authorized_keys2

Change the permissions of .ssh to 700
Change the permissions of .ssh/authorized_keys2 to 640