Sponsored

Not the solution you were looking for?

We’ll help you out!

How to disable remote login for root user on Linux machine

These days by default a user called root would be created on every Linux system. In distros like RHEL, fedora, CentOS during installation itself, you would be asked to create the default root account. The default ssh configuration allows all users to login to your server remotely. If a hacker try to brute force your root user password, then he would gain access to your system completely ! So for security reason, it’s not a good idea to have enabled remote login to root user. In this tutorial we would see how to disable remote login for root user on a Linux server.

There are two config files “ssh_config” and “sshd_config” under /etc/ssh/ directory. ssh_config file contains configuration pertaining to outbound SSH connections. where as sshd_config file contains configuration parameters which controls inbound SSH connections to the server itself.

Note : It’s always a good idea to backup important system files before you modify.

First we shall block root login from remote server. Open /etc/ssh/sshd_config file in your favorite text editor and find the line labeled PermitRootLogin. It will most likely be commented out using the # symbol as shown in the below image :

Disable Root Login on Linux Server

Remove the # symbol to make the line active, and then change “yes” to “no” as shown in the below image :

Disable Root Login Linux Server

After modification, do not forget to restart the sshd service as shown below :