I find myself always having to search for the steps to do key authentication for ssh. This post is to be a personal quick reminder of the required steps. See link here for a more detailed walk through.

  1. Generate private/public key pair on the local computer.

    ssh-keygen -t rsa -b 4096

    The 4096 is just for a longer key for security reasons. By default, this stores the keys at ~/.ssh in the files id_rsa and id_rsa.pub.

  2. Transfer the public key to the remote computer that you are attempting to ssh into.

    ssh-copy-id user@host

    You’ll need to enter in the user’s password at this step. If all goes according to plan, at this point, you should be able to do ssh user@host and not enter in a password.

    Update: In some instances you are given an initial private/public key pair to the server, with no password. In that case, you still need to get the public key to the server using existing ssh access. Just copy the line from id_rsa.pub to the ~/.ssh/authorized_keys file for the user logging in as.

  3. Give the hostname/IP address an alias so that it is easier to remember.

    You can alias the IP address for ssh using the ~/.ssh/config file. For example, to ssh into the server that hosts my psychrometric chart page, I have the following lines (not the actual IP address).

Host psy
    User root

With those lines added to the ~/.ssh/config file, I can now use the command

ssh psy

and I’m in.