Disable root login is a security measure that can be used on a Linux server.
One of the biggest security holes you could open on your server is to allow directly logging in as root through ssh, because any cracker can attempt to brute force your root password and potentially get access to your system if they can figure out your password.
It’s much better to have a separate account that you regularly use and simply sudo to root when necessary.
Execute the following commands as root user :-
Add a new user
# adduser user
Set the user’s password
# passwd user
Add the user to the ‘wheel’ group
# usermod -G wheel user
Before disabling the root login, login as wheel user on another terminal to ensure that everything is working fine.
Switch back to root user using the su command
Now we need to disable root login through SSH
Open the ssh main configuration file in the server
Search for the below line:
Modify it and change it to:
Now restart the service.
systemclt restart sshd
Make sure that you are able to access the the server as ssh user and switch to root without closing your current ssh root session.
Powered by BetterDocs