Skip to main content

Ubuntu: Installing SSH Keys

Here's some steps on how to install SSH public keys in a host.

1. SSH Key Folder

Navigate to the home folder for the user, with the following command:

cd /home/username

Check if the .ssh folder exists (it is hidden, requiring the -a switch):

ls -al

If the .ssh folder does not exist, create it with the following commands (from the user folder):

sudo mkdir ~/.ssh
sudo chmod 0700  ./.ssh

2. SSH Key File

Enter the ssh key folder with:

cd ./.ssh

And, check if any key files are there, with:

ls -l

image.png

Make sure the key file has the same name that was defined in the ssh config file, in previous steps.

If no key file, create one with (making sure to use the correct key file name):

sudo touch ./authorized_keys
sudo chmod 0644 ./authorized_keys

The tricks to successfully pasting in an SSH key to the ssh key file are:

  • Always paste the key string as a single line

  • The key string must being with, “ssh-rsa“

  • Strip out any “Begin SSH2 PUBLIC KEY” and ending

  • The key line should contain the key comment at the end of the line, for easy identification

  • A key string should be of the form: ssh-rsa [really long base64 key string here] [key comment]

  • Single whitespace is needed between each component of the key line

  • The key comment must have no whitespace in it

The easiest way to get this string is to load a key in PuttyGen.
Then, paste the entire key string directly from the text window of the form, like this:

image.png

Connecting to SSH Server from Windows

See this page for steps on how to connect to a Linux host from Windows: Connecting to SSH Server from Windows