Disable SSH Login for the Root User on CentOS / RHEL

Published on September 8, 2019 24 sec read

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. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

Hey, I'm Md Obydullah. I build open-source projects and write article on Laravel, Linux server, modern JavaScript and more on web development.