Debug School

rakesh kumar
rakesh kumar

Posted on

How to disable root login for securing linux server with example

Disabling root login is a good security practice that can help protect a Linux server from unauthorized access. Here's how you can do it on a Linux system:

1.Log in to your Linux server as a user with administrative privileges.

2.Open the SSH configuration file using a text editor such as nano or vi. The location of this file may vary depending on your distribution, but it is usually located in /etc/ssh/sshd_config.

For example, to open the file using nano, run:

sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

3.Locate the line that contains "PermitRootLogin" and change its value to "no". This line may be commented out, so you will need to uncomment it by removing the "#" symbol at the beginning of the line.

#PermitRootLogin yes
Enter fullscreen mode Exit fullscreen mode

After:

PermitRootLogin no
Enter fullscreen mode Exit fullscreen mode

4.Save the changes to the SSH configuration file and exit the text editor.

5.Restart the SSH service to apply the changes by running the following command:

sudo service sshd restart
Enter fullscreen mode Exit fullscreen mode

With these steps, you have successfully disabled root login. From now on, users will not be able to log in directly as root via SSH. Instead, they will need to log in as a regular user and then use the "su" command or "sudo" to gain root privileges. This is a good security practice that can help prevent unauthorized access to your Linux server.

Top comments (0)