Password-less Login Using SSH

Consider we want to login from a MacBook Pro (mbp) to a remote Linux machine (tsingyi), where both computers have OpenSSH installed. In order to make tsingyi trust mbp, we use RSA cryptographic method to generate a public and a private key for mbp, which will be used to identify mbp during login.

To generate the pair of keys, on mbp, type

ssh-keygen -t rsa

Accept all default answers, and we get two files:

~/.ssh/id_rsa     --- the private key
~/.ssh/id_rsa.pub --- the public key

Now, copy the public key file to tsingyi by typing following command on mbp:

scp ~/.ssh/id_rsa.pub wyi@tsingyi:/home/wyi/.ssh/id_rsa-mbp.pub

and add the public key of mbp to ~/.ssh/authorized_keys of tsingyi by typing following command on tsingyi:

cat ~/.ssh/id_rsa-mbp.pub >> ~/.ssh/authorized_keys

Here we are. We should be able to ssh to tsingyi from mbp without typing password now.