How to disable root login via ssh

Having your root enabled login via ssh is not a good ideea. Root is the is the most privileged account on a Unix system. If you are signed in or using the root account the system shell, bash, prompts “#” as the last character. With a normal user the last character is “$”. You can say that Linux itself is showing us a warning.

So how do we disable the root login via ssh?

Step one. Create a new user

Let’s say that we want to add the user “cfc” to a server. We ca use the following command:

adduser cfc

Now we need to set a password also. You can do it with the following command:

passwd cfc

Step two. Give the new user sudo rights.

To allow the new user to make changes to the system he needs to be in sudo group. Type the following command:

usermod -aG wheel cfc

This command is for RHEL distributions.

Step three. Disable ssh root login.

Now that we have our new user with sudo privileges we can disable root ssh remote login. We need to find the disable root login inside sshd_config.

nano /etc/ssh/sshd_config
# Authentication:

#LoginGraceTime 2m
PermitRootLogin no

Restart ssh and login with your new user.