How to Disable or Enable SSH Root Login in Linux
- Last updated: Nov 3, 2023
- Views: 168
- Author: Admin

Hello colleagues.
In today's article, we'll talk about how you can disable or enable SSH authorization directly to the root account in the Linux operating system.
As everyone may know by default, after installing Linux, you can connect to the server through the root account directly using the SSH protocol. For security reasons, I do not recommend that you enable this feature for unauthorized users, because an evil hacker can try to guess the password and thereby gain full access to your server.
The best option would be to create a separate account under which you will often connect to the server, and then from under this account through the command "sudo -i" switch to root.
And so, in order to disable the ability to log in with the root account, we need to edit the main SSH configuration file called sshd_config.
Open the sshd_config file for editing with the command:
$. vi /etc/ssh/sshd_config
We find the PermitRootLogin parameter and remove the comment and change the parameter values from yes to no.
PermitRootLogin no
We save the changes.
After we have changed the parameter values, we definitely need to restart the SSH service for our changes to take effect.
To restart the SSH service, use the command:
$. systemctl restart sshd
Now when we try to access the servers as root in a new session, we will get an Access denied error.
In order to get everything back, you need to change the PermitRootLogin parameter from no to yes in the main sshd_config file, and restart the SSH service.
Thank you all, I hope my article was of some help to you.