Disable root login

It’s a bad idea to login with your superuser. There are too many bots running and trying to hijack your server. You don’t need to make it easier for them to take over your server. Therefore you should disable the root login via SSH.

The first step is to create a user and a password for the ssh login with the following commands:

# adduser user1

Then we need to give the new added user the sudo permission. This can be done by enter following command:

echo 'user1 ALL=(ALL) ALL' >> /etc/sudoers

Important: Try to login with your new added user via SSH. If it works, you can process the next step. Otherwise, stop here and try to figure out what isn’t working. If you ignore this hint, you are not able to login to your server with any user.

To disable the root login, open the following file:

# sudo nano /etc/ssh/sshd_conf

Find the following directive and change it to the following value:

PermitRootLogin no

Don’t forget to save the file before you close it. The last step is to restart the service with the following command so that your change will be activated.

# sudo systemctl reload ssh

Important: Don’t log out yet! Try to login with your previously created user, again. If it works you can safely log out the root user.

If you try to logon with the root user, you will get a permission denied message.

chevron_left
chevron_right

Leave a comment

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

Comment
Name
Email
Website

This site uses Akismet to reduce spam. Learn how your comment data is processed.