SSH login without password
Problem : SSH login without password
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login
from host A(amitmaheshwari.in) user "tom" --> to Host B (xyz.com) user "jim".
You don't want to enter any passwords, because you want to call ssh from a within a shell script.
Solution : How to do it
First log in on A as user tom and generate a pair of authentication keys. Do not enter a passphrase:
email@example.com:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tom/.ssh/id_rsa):
Created directory '/home/tom/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tom/.ssh/id_rsa.
Your public key has been saved in /home/tom/.ssh/id_rsa.pub.
The key fingerprint is:
Now use ssh to create a directory ~/.ssh as user jim on xyz.com. (The directory may already exist, which is fine):
firstname.lastname@example.org:~> ssh email@example.com mkdir -p .ssh
Finally append tom's new public key to firstname.lastname@example.org:.ssh/authorized_keys and enter jim's password one last time:
email@example.com:~> cat .ssh/id_rsa.pub | ssh firstname.lastname@example.org 'cat >> .ssh/authorized_keys'
From now on you can log into B as jim from A as a without password:
email@example.com:~> ssh firstname.lastname@example.org
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