How to configure ssh key authentication for root Linux (Ubuntu | Debian | Centos) CLI.

This is a quick reference guide on how to configure ssh key authentication for root on Linux Based Operating Systems.

1. Generate a public and private key pair using puTTYgen

Please see examples of the public and private key – you can use these to test.

Public Key

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEA0Xw9YhMethjXaHrTWK+Iys3g8Iiu6xCsQMD812s1KzYXeuVZFc1GFF5V48aTZdlv6UucQA4V0tQ0zOGJC3S8jBrtxzTFTTB8PZE10K/Xl60rwJOIS2FC/QqP37kk13RVVIliKwUSbafeq19tWd8yJ1SpIH44EjUZFpDcakukpO1R9QdPtaN9VJJMb1MrPTdLEYpSOtcrniZSlE9aB/CABFYFBcTsMNDz8BAEntpZEUM+KoaQ1GAPo4qYywrFr9sCdhAvhjwYpytSneWwcpPvb0DLVevJO7b0DaGPKOKD4EFxzHnkJVFOKtyvUyuchAhNn0dd85wtbA2vr5uyz/PT0Q== rsa-key-20190521

Private key

2. Paste the public key string into /.ssh/authorized keys

root@VPS:~/.ssh# ls
root@VPS:~/.ssh# nano authorized_keys

3. Configure passwordless SSH

root@VPS:~# cd /etc/ssh/
root@VPS:/etc/ssh# ls
moduli                  ssh_host_ed25519_key      ssh_import_id
ssh_config      sshd_config
ssh_host_ecdsa_key      ssh_host_rsa_key          sshd_config.ucf-dist
root@VPS:/etc/ssh# nano sshd_config
PasswordAuthentication no
PermitRootLogin without-password

4. Restart sshd

root@VPS:/etc/ssh# service sshd restart

5. Configure Putty

You will need to select the private key for authentication. Just select the private key file you have generated using puTTYgen. You can use the file TEST that I have inserted into this document to test. Please note that you need a key pair to authenticate, so a public key on your server and the private key configured on your putty.

Once this is configured you connect normally using ssh and entering the username root.

You will get the following error if you do not have a private key configured on your putty session.

Thank you for reading and please feel free to leave any feedback.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s