Tuesday 10 January 2012

SSH without Password

At times situations occur that we need to copy files from a machine or a server to another through ssh or scp using a script. We might not be able to enter a password all the time ,eg. in a situation where the script that does this job runs through Crontab.

In such situation we might require that ssh or scp to be performed without requiring to enter a password to access the machine.

The following method can be used to connect two servers or machines without password.



Assume two machines MC1 and MC2.

1. Log into the machine MC1. We have to generate a pair of authentication keys.
(Do not Enter Pass phrase in this step)

user1@MC1:~> ssh-keygen -t rsa



Generating public/private rsa key pair.

Enter file in which to save the key (/home/a/.ssh/id_rsa):

Created directory '/home/a/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/a/.ssh/id_rsa.

Your public key has been saved in /home/a/.ssh/id_rsa.pub.

The key fingerprint is:

3e:4f:05:79:3a:9f:96:7c:3b:ad:a9:51:37:bs:36:e4 a@A





2. Using ssh create a director ~/.ssh on MC2. Most Probably the directory will be present.

user@MC1:~> ssh user2@MC2 mkdir -p .ssh
user2@MC2 's password :

3. Add user1's new public key to user2@MC2: .ssh/authorized_keys


user1@MC1:~> cat .ssh/id_rsa.pub | ssh user2@MC2 'cat >> .ssh/authorized_keys'
user2@MC2's password: 



That's all!!!!!!

Now it will be possible to ssh between MC1 and MC2 without a password.





No comments:

Post a Comment