How to Disable Root Login on Ubuntu 20.04

If you followed our Ubuntu 20.04 - Initial Setup, you created a sudo user so you would not login as root. To further secure the server, we should make it so that no user can login as root under any circumstances.

Step 1 - Open SSH Config

$ sudo nano /etc/ssh/sshd_config

Scroll down until you see the following:

PermitRootLogin yes

and change it to:

PermitRootLogin no

Now save the file by hitting [CTRL-X] then Y, then [ENTER]

Finally, restart the sshd server:

$ sudo systemctl reload sshd

That is it, root can no longer login to your server.

If You Are Using an SSH Key To Login

If you have setup a key, and are not using a password to login, go ahead and open sshd_config again, and find this line:

PasswordAuthentication yes

and change it to:

PasswordAuthentication no

You may see this command in several areas of the file. Make sure you only have it uncommented and set to no in one place.

Then save the file again and restart the service as you did above. This will make it so that an SSH key is required to login to you server, securing it that much more from possible intruders.

Blog Comments powered by Disqus.