Monday, June 21, 2010

Ssh to another host w/o providing password

On the source host, do:
ssh-keygen -t dsa
when prompted to enter a passphrase, simply press the <Enter> key, which provides an empty passphrase.

A pair of files will have been generated:
~/.ssh/id_dsa
~/.ssh/id_dsa.pub
The following commands on the source host may be optional:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_dsa*
Copy the second, generated file over to the target host, providing password when prompted as normally done:
scp -p ~/.ssh/id_dsa.pub <target_hostname>:
On the target host, append the file to ~/.ssh/authorized_keys:
cat ~/id_dsa.pub >> ~/.ssh/authorized_keys
The following commands on the target host may be optional:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
rm -f
~/id_dsa.pub
Now we are all set to be able to ssh (and scp, etc.) from the source host to the target one without having to provide password. The procedure can be done symmetrically by swapping the source versus target hosts.

This is particularly useful when there is a large swath of target hosts and a same thing is to be done on them one by one, by using the source/current host as a base.

Notes on hosts:
Source: RHEL/AS/3u3 (kernel: 2.4.21-20.ELsmp #1 SMP)
Target: RHEL/5.2 (kernel: 2.6.18-92.el5 #1 SMP)