Disable SSH Login for the Root User on CentOS / RHEL

Published on Sep 08, 2019

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:

#PermitRootLogin no

3. Remove the hashtag sign (#). After doing this, it should look like this:

PermitRootLogin no

Now we need to restart the SSH daemon service. Here are the commands to restart SSH daemon service:

sudo systemctl restart sshd
# Or,
sudo service sshd restart
# Or,
sudo /etc/init.d/ssh restart
That’s all. Now you’re unable to login with root account. ?

Comments (0)