Tuesday, July 14, 2009

Passwordless ssh

1)Let say both machine with user tux.
2)login to machine A, with "tux"
3)Generate RSA key.

ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/tux/.ssh/id_rsa): # Press 'enter' here
Enter passphrase (empty for no passphrase): # Press 'enter' here
Enter same passphrase again: # Press 'enter' here
Your identification has been saved in /home/tux/.ssh/id_rsa.
Your public key has been saved in /home/tux/.ssh/id_rsa.pub.
The key fingerprint is:
Example:
40:01:53:a3:fe:6c:91:24:e9:ed:a1:26:ac:e4:96:67 user@host

4) Ensure the public key id_rsa.pub is created in folder .ssh

5)Copy the key to machine B
scp ~/.ssh/id_rsa.pub tux@machineB:~/.ssh

With this command will copy the key to remote host /home/tux/.ssh

6) Login to machine B with tux, and run this comment to append the key to authorized_keys
cat id_rsa.pub >>~/.ssh/authorized_keys
rm id_rsa.pub


note: the permission for authorized_keys must set to 600. To change it try >chmod 600 authorized_keys

7) Done. Try to ssh to machine B without password entered.

P/S: This approach is applicable to different users. Let say tux1 and tux2. To connect to machine B with tux2. Follow the step 1 to step 6 to copy the tux1's public key to tux2, and connect with command tux1> ssh tux2@machineb. DONE!!!

No comments:

Post a Comment