You’re used to ssh-ing into machine B from machine A by typing:
Now you wish to ssh from machine A into machine B without having to enter your password. Just follow these steps.
Create a public/private RSA key pair by issuing the unix command
ssh-keygen. Do not enter a passphrase.
Put the private key on machine A (the machine you wish to ssh from). Usually the best place to put it is in
On machine B, create the file
~/.ssh/authorized_keys. Add the public key as a line to this new file. You can do this with the command
cat public_key >> authorized_keysor by copy/pasting.
On machine A, create the file
~/.ssh/config. Add the following to this file.
That’s it. You can now passwordlessly ssh into machine B from machine A just by typing:
And as a bonus, you can now
scp to and from machine B passwordlessly as well.
I’m posting this online because it’s something I wish I had known sooner. Hopefully you can benefit from it.
This post isn’t the whole story though! Using an ssh key without a passphrase (a la step 1) is dangerous; if anyone gains access to your private key then they’ll be able to ssh into machine B as you. The solution is to (back in step 1) create a passphrase for your private key, and then ssh-agent will remember your decrypted private key so that you don’t need to enter your password too often.