≡ Menu

Linux: Openssh (ssh server) deny root user access

Q. How do I block access to root user over ssh session?

A.. sshd (OpenSSH Daemon) is the daemon program for ssh. Server side ssh configuration is defined in /etc/ssh/sshd_config file.

You need to use DenyUsers option to block access to root user.

This option can be followed by a list of user name patterns, separated by spaces. Login is disallowed for user names that match one of the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts.

Open /etc/ssh/sshd_config file

Use vi command:
# vi /etc/ssh/sshd_config

Deny root user access

Append or modify as follows to block root user:
DenyUsers root

If you want to block additional user just append names to DenyUsers
DenyUsers root, user2, user3

Save and close the file. Restart sshd service:
#/etc/init.d/sshd restart

{ 3 comments… add one }

  • slashx August 28, 2007, 9:42 am

    in /etc/ssh/sshd_config
    setting this:
    PermitRootLogin no

    should also do the same thing, but denyusers works too :)

  • Wasim March 15, 2013, 5:18 am

    Nice Blog…

  • Wasim March 15, 2013, 5:21 am

    vi /etc/ssh/sshd_config
    Find the below line first
    #PermitRootLogin yes
    Add a new line below this entry
    PermitRootLogin no

Leave a Comment

   Tagged with: , , , , , , , ,