To deny root user access or log in to a Linux system using OpenSSH, you can modify the PermitRootLogin
directive in the sshd_config
file.
By default, the PermitRootLogin
directive is set to yes
, which allows root user login using OpenSSH. To disable root user login, you can set the PermitRootLogin
directive to no
.
Here is an example of how to disable root user login using OpenSSH:
sshd_config
file in a text editor:sudo nano /etc/ssh/sshd_config
PermitRootLogin
directive and set it to no
:PermitRootLogin no
Save the file and exit the text editor.
Restart the OpenSSH server to apply the changes:
sudo systemctl restart ssh
This will disable root user login using OpenSSH. Keep in mind that this will not prevent root user login through other methods, such as local console or serial console login. To disable root user login completely, you will need to take additional measures, such as disabling the root user account or modifying the /etc/securetty
file.
It is also important to note that denying root user login using OpenSSH can make it more difficult to perform certain system maintenance tasks, as you will need to log in as a non-root user and use sudo
to execute commands with root privileges. Make sure that you have a non-root user with sufficient privileges to perform these tasks before disabling root user login.