Setting up SSH Key Authentication on Linux

This will guide you through setting up SSH Key authentication to your Linux Cloud SWhile password authentication can be made secure with complex passwords, changing the SSH port, and disabling the root user, it is best to make use of SSH keys for accessing your Cloud Server. You use these to protect your cloud server against brute force password attacks by using a public-private SSH key pair. 


The following steps will guide you through setting up SSH Key authentication to your Linux Cloud Server from your Linux based workstation. All commands are run from your workstation. Not your Cloud Server.

Run the following command to generate an SSH key.

# ssh-keygen

This will prompt you to set a location for the keys. The default location is the ~/.ssh directory, and the default filenames would be id_rsa for the private, and id_rsa.pub for the public. Unless you’re very familiar with the process, it’s best to use the default locations so that no additional configuration would be needed. Pressing ENTER on the keyboard should tell it to advance using the default locations.

After you choose the location, you’ll be prompted to enter a passphrase which will encrypt the SSH key file on your machine. You can choose to enter one, or press ENTER to skip this process. If you do choose to encrypt the key, you’ll be asked for the password each time you authenticate with the key.

Next, you’ll want to copy the public key onto the server you wish to use the SSH Key authentication on.

Run the following command to copy the key to your server.

# ssh-copy-id @

Once done, test that this was successful by SSHing into your Cloud Server. You should not be prompted for a password (unless you encrypted the key).

# ssh @

For more on securing SSH, have a look at this guide here.

Leave a Reply

Your email address will not be published. Required fields are marked *