SSH login without password

Our Aim :
        You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.


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


senthil@linux-5xxh:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/senthil/.ssh/id_rsa): senthil
senthil already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in senthil.
Your public key has been saved in senthil.pub.
The key fingerprint is:
fd:35:b7:1d:25:1d:a5:cd:59:71:fd:a2:8a:62:bb:a1 senthil@linux-5xxh

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



senthil@linux-5xxh:~> ssh siva@192.168.2.20 mkdir -p .ssh
Password:


Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:



senthil@linux-5xxh:~> cat .ssh/id_rsa.pub | ssh siva@192.168.2.20 'cat >> .ssh/authorized_keys'
Password:



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



senthil@linux-5xxh:~> ssh siva@192.168.2.20
Last login: Fri Feb  4 12:19:38 2011 from senthil
siva
@maxima
:~>




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


LinkWithin

Related Posts Plugin for WordPress, Blogger...