Setting up SSH keys for authentication

Encrypted cloud connection

This article will show you how to set SSH keys for authentication on a linux machine.

SSH keypairs are combination of a public key that you set on your remote machines and a private key that you shoud store securely and use for accessing the remote machines. They add both better security than passwords and less effort to remember different password for each server you log on.

Once you have one, you’ll get two files the private key which you should keep very secure and safe and the public one which you can provide and share publicly without concerns.

To use your SSH key for authentication you add your public key to the remote machines authorized keys.

It’s a file in the .ssh folder, in the home directory of your user, ex.:

/home/admin/.ssh/authorized_keys

If the file doesn’t exist, simply create it.

nano ~/.ssh/authorized_keys

or

vim ~/.ssh/authorized_keys

Add your private key to the authorized_keys file, it will look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFM9wOKgSxS1WlsOYMqScJuvwyJQ1cKD7Vqh46+LwuxTo0mVKs25JKrn6F0Wn7Ua3Ghb3BiW7BzLWm9kh3/0X6R+lvJe52g/bO347JzUBsZC8kiwz2IuYgwyAT9eILBcVCcuSKisPTTFlhlzOonKefQvRmECzbdLxJR0xn30Z18tVtdazwexPU46/EwlKhB0TWfCtm8LuOMbAIhIK61z8dgL+BB0pHfzeuJdbhbqDFNq9sF8B80lNEmhq7pFyTOyb1isXvLKbVzyp1uLWJJUgQMZYhem4XCltosjr7EvDlPEfW6pQXskyJGOJ1U4BUZrMxYzBaFYwQp8syqTfgm4Vf admin@ubuntu

You can add more than one authorized key per user, just put each of them on a new line.

With that done, you are now authorized to connect using your private key.

Comment (1)

  • How to use Rsync for file synchronization between servers - CloudBalkan| May 13, 2018

    […] you are using SSH keypairs authentication on your servers, this is an example how to specify the private key to be used for the SSH […]

  • Leave a Reply

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