Remote login without password

by saikrishbe

Suppose you have a login as ‘A’ in host ‘AA’ and another login ‘B’ in host ‘BB’ and you often have to switch between these logins with SSH. It feels irritating to give the password every time. There might also be situations when you need to run a shell script that manipulates the resources in the other login.

You can login using SSH without any password by doing this-

A@AA~$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/A/.ssh/id_rsa): <press enter >

Enter passphrase (empty for no passphrase): <press enter >
Enter same passphrase again: <press enter >
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:e9:58:37:bc:37:e4 A@AA
Then type this:

A@AA~$ ssh B@BB mkdir -p .ssh

password: <enter B’s password>

Then append the public key produced in .ssh/id_rsa.pub (in A) to .ssh/authorized_keys file in B.

This is done as follows:

A@AA~$ cat .ssh/id_rsa.pub | ssh B@BB ‘cat >> .ssh/authorized_keys’

password: <enter B’s password for the last time>

Now you login into B through ssh by just typing :

A@AA~$ ssh B@BB

B@BB~$

Thats it!