How to allow root to login with ssh key

When you are managing multiple Linux servers, one of the safest and best ways to login to your server is via SSH secure key. Also, if your company has several administrators and one is leaving the company, the best way is to disable it's SSH key. Also, another benefit from the SSH key is that you don't need to remember several passwords. How to generate SSH key you can read into this how-to click here, but how to add a user with SSH key you can read here.

1. Login to your Linux server as root and go to user folder

cd /root/

2. Create a .ssh directory in the root home directory and change its file permissions to 700.

mkdir /root/.ssh ; chmod 700 /root/.ssh

3. Create the authorized_keys file in the .ssh directory, and then restrict file permissions to 600 to enforce that only the root has read or write access to the file.

touch /root/.ssh/authorized_keys ; chmod 600 /root/.ssh/authorized_keys

4. Add the user public key.

nano /root/.ssh/authorized_keys

Now, this example shows, how to add SSL key for a root user.

But if you need an SSH key for a different user, you can read it here.

How to generate an SSH key on Linux and macOS you can find here.