Automatic remote login

30 Oct 2018

Remote login without a password is more secure than a password1, and can be set up in a few minutes. Basically you generate a public/private key pair and copy the public key to the remote computer you want to log into. The private key stays on the computer you’re logging in from.

The following instructions assume your user name is Stuart and the remote computer is at erewhon.com, and you’re using either Linux or MacOS.

  1. Generate a public and private RSA key pair. If you’ve done this once before, skip this step and step 2.

    mkdir ~/.ssh
    ssh-keygen -t rsa
    

    When it asks for a passphrase just hit Return. You now have an id_rsa private key and an id_rsa.pub public key in the ~/.ssh directory.

  2. Make the private key readable only by you.

    chmod 600 ~/.ssh/id_rsa
    
  3. Copy the public key to the remote computer.

    scp ~/.ssh/id_rsa.pub stuart@erewhon.com
    
  4. Install the public key on the remote computer.

    ssh stuart@erewhon.com
    mkdir ~/.ssh
    cat id_rsa.pub >> ~/.ssh/authorized_keys
    rm id_rsa.pub
    chmod 700 ~/.ssh
    

Log out of the remote computer and you should be able to log back in without a password.


  1. Passwords tend to be short so you can remember them, maybe 10 to 15 characters. An RSA public key can be around 400 characters, much more difficult to brute force (trying every combination).