How to prevent or disable root user from logging in via SSH?
For security reason ssh root access should be disabled for unauthorized users. Because a hacker can try brute force attack to crack your root password and gain access to your server. The securing root user is one of the most important tasks for system administrators. Direct root logins should only be allowed if you have physical access to the system.
Note: Before you disable root logins via SSH. Make sure you should add a user which can ssh into the server and become root by using the su command.
1.) Login as a root user via SSH
ssh [email protected] address or domain name
2.) Edit the SSH daemon’s configuration file
3.) Uncomment PermitRootLogin yes and change it to no or simply add PermitRootLogin no
PermitRootLogin yes Change it to: PermitRootLogin no
4.) Save configuration file.
You can save the file in vim by pressing
Then press enter.
5.) Restart the service
To restart sshd service use the command below
/etc/init.d/sshd restart or systemctl restart sshd or service sshd restart
If you find this post helpful, please share it on your social networks. If you have any questions? Leave a comment below.