If you want to login from host_A (user a) to Host_B (user b), it is annoying to enter passwords everytime, because you want to call ssh from shell script.
Ok it’s quite easy to do that:
Generate public key
First in host_A you need to generate a pair of authentication keys;
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
The key's randomart image is:
+--[ RSA 4096]----+
| .oo.. |
| E .o . |
| . +.+ = |
| . + +.* B |
| . . + oS* . |
| . . + |
| . . |
| . |
Create .ssh directory in host_B
Create a directory ~/.ssh as user b on host_B. (The directory may already exist, which is fine):
a@A:~> ssh b@B mkdir -p .ssh
Append a’s public key to b
Append a’s new public key to b@B:.ssh/authorized_keys and enter b’s password one last time:
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
Voilà, from now on you can log into B as b from A as a without password: