Configure SSH access into an Ubuntu Server

The following notes are a subset of the information provided in this tutorial.

Prerequisites

  • An instance of Ubuntu Server running.
  • An account on the server that can be elevated to root and that you know the password for.

Create an SSH Key pair

The tutorial does this manually on the command line which is fine, however you can also use PuTTYGen:

  • Optional - change the bits to 4096.
  • Click Generate.
  • Copy the contents of box (something like ssh-rsa AAAAB3NzaC1…) into a file with a .pub extension. This is simplest option to avoid some of the file format gotchas in this question.
  • Click Save private key and save to a file with the same name as the previous one but with no extension.

Copy the public key to the remote Ubuntu Server

You should be able to run the following (exactly as shown in the tutorial):

cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address/your_domain.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Remember which key file to use with the domain

  • Open .ssh directory under your user folder (or create it if it does not exist).
  • Open the config file (or, again, create it if it does not exist).
  • Add the following:
Host server_ip_address/your_domain.com
  HostName server_ip_address/your_domain.com
  User remote_user
  IdentityFile /home/localuser/.ssh/your_key_id_rsa
  IdentitiesOnly yes

References

Written on January 16, 2020