Your Goal
You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from Host-1/user-A to Host-2/user-A. You don't want to enter any passwords, because you want to call ssh from within a shell script.
How To Accomplish It
First log in onto Host-1 as user-A and generate a pair of authentication keys. Do not enter a passphrase:
ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/a/.ssh/id_rsa): Created directory '/home/a/.ssh'. 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: 3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory ~/.ssh as user-A on Host-2. (The directory may already exist, which is fine):
ssh user-A@localhost mkdir -p .ssh user-A@localhost's password:
Finally append user-A's new public key to user-A@Host-2:.ssh/authorized_keys and enter user-A's password one last time:
cat .ssh/id_rsa.pub | ssh user-A@Host-2 'cat >> .ssh/authorized_keys' user-A@Host-2's password:
From now on you can log into Host-2 as user-A from Host-1 as user-A without a password:
ssh user-A@Host-2 hostname user-A@Host-2:~>
