If you want to use Linux and OpenSSH to automate your tasks, it is really convenient not to enter a password every time you ssh onto one host. So let describe a bit the architecture. You have a client host, and a remote host and you need an automatic login from :
clientHost as clientUset onto remoteHost as remoteUser, and all this without entering any passwords, because you want to call ssh from a within a shell script or terminal.
This is how to do it
We'll first need to generate a pair of authentication keys for which we will NOT enter a passphrase:
clientUser@clientHost:$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/clientUser/.ssh/id_rsa): Created directory '/home/clientUser/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/clientUser/.ssh/id_rsa. Your public key has been saved in /home/clientUser/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Qw0SGcwwwwwwwww clientUser@clientHost
Now use ssh to create a directory ~/.ssh as user remoteUser on remoteHost. If the directory already exist, this means that it is ok, because we only wanted to make sure that this directory exist).
clientUser@clientHost:$ ssh remoteUser@remoteHost mkdir -p ~/.ssh remoteUser@remoteHost's password:
Now the directory on the remote host is created. We will then append a new public key to the authorized keys on the remote host. For this we'll do as follow:
clientUser@clientHost:$ cat ~/.ssh/id_rsa.pub | ssh remoteUser@remoteHost 'cat >> ~/.ssh/authorized_keys' b@B's password:
OK, so now, you can log into remoteHost as remoteUser from your clientHost as clientUser without entering any password, and just by typing inside of your script or terminal, the following ssh connection command:
clientUser@clientHost:$ ssh remoteUser@remoteHost
Well done guys, you're ready to SSH simply!