Disable SSH Login for the Root User on CentOS / RHEL
In this short article, I’ll show how to disable SSH root login on CentOS / RHEL server. Let’s see:
Note: You should create a user with root access before doing this.
1. Open SSH configuration file using this command:
sudo nano /etc/ssh/sshd_config
2. Search for the following line in the SSH configuration file:
3. Remove the hashtag sign (#). After doing this, it should look like this:
Now we need to restart the SSH daemon service. Here are the commands to restart SSH daemon service:
That’s all. Now you’re unable to login with root account. ?
sudo systemctl restart sshd # Or, sudo service sshd restart # Or, sudo /etc/init.d/ssh restart