SSH Root user login access is enabled in any system by default. Or we are asked while installing a system. that you have to enable or disable ssh root user login access. And you never know how to enable and disable ssh root user login access. So in this tutorial, we will show you how you can enable and disable SSH root user login access from the command line.
Enable or Disable SSH Root Login Access in Linux
Use the following ways to enable or disable ssh root login access in Linux:
- Disable SSH Root Login
- Enable SSH Root Login
Disable SSH Root Login
If SSH root user login access is enabled in your system and you do not know how to disable SSH root user login. So you can disable root user login access using the following commands.
First of all, open the terminal and execute the following command into it to open the main ssh configuration file /etc/ssh/sshd_config:
vi /etc/ssh/sshd_config
In the file opened with the upper command, search for the following line:
#PermitRootLogin no
Remove the ‘#‘ from the beginning of the line. Make the line look similar to this:
PermitRootLogin no
After that restart your server. So that is what you have changed in your file. It makes changes done:
# systemctl restart sshd OR # /etc/init.d/sshd restart
After all, you’ve now disabled the SSH root user login. You will no longer be able to access the root user login. You can also see this by trying it.
When you try to log in with the root user, Denied will be displayed in your terminal. Why have you disabled your root user login access?
Enable SSH Root Login
If SSH root user login access is disabled in your system and you do not know how to enable SSH root user login. So you can enable root user login access using the following commands.
Now, open a terminal and execute the following command into it to open the main ssh configuration file /etc/ssh/sshd_config:
vi /etc/ssh/sshd_config
In the file opened with the upper command, search for the following line:
#PermitRootLogin yes
Remove the ‘#‘ from the beginning of the line. Make the line look similar to this:
PermitRootLogin yes
After that restart your server. So that is what you have changed in your file. It makes changes done:
# systemctl restart sshd OR # /etc/init.d/sshd restart
After all, you’ve now enabled the SSH root user login. You will be able to access the root user login. You can also see this by trying it.
When you try to log in with the root user, The Access grant will be displayed in your terminal. Why have you enabled your root user login access?
Conclusion
Through this tutorial, You have learned how to enable and disable ssh root login and limit ssh access in Linux.