Tuesday, October 16, 2012

Password-less ssh login




ssh from machine1 to machine2 should be password-less (say for some automation tasks)

user1@machine1>pwd
/home/user1/.ssh/
user1@machine1> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 user1@machine1
user1@machine1>cat ~/.ssh/id_rsa.pub | ssh user1@machine2 'cat >> ~/.ssh/authorized_keys && chmod 640 ~/.ssh/authorized_keys'
user1@machine2's password:
user1@machine1>ssh user1@machine2
user1@machine2>hostname
machine2