Let user@ServerA be the host that wants to connect to user@ServerB.
Run the following commands as user@ServerA
ssh-keygen -t rsa # use empty pass phrase, save the keys to ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub chmod 700 ~/.ssh # set the permissions of the .ssh directory to 700. chmod 600 ~/.ssh/* # set the permissions of the keys so no one else can read them.
It’s important to set the permissions! Otherwise SSH will not use the keys without a warning or message. I’ve wasted enough time to learn this the hard way.
Copy the ~/.ssh/id_rsa.pub from user@ServerA to user@ServerB:~/.ssh/authorized_keys. Again, set the permissions.
chmod 700 ~/.ssh # set the permissions of the .ssh directory to 700. chmod 600 ~/.ssh/* # set the permissions of the keys so no one else can read them.