in openssh, you can restrict root login (PermitRootLogin no) but can it have an exception?

  • But that would mean that root login was permitted ... why not login as a user and then su / sudo? – pjc50 May 29 '12 at 13:13
  • I'm sorry, but what exception? Either you permit root login or you don't. – Dennis May 29 '12 at 13:13

Given that logging in as root is not a good idea, have a look at sshd manpage:


Specifies whether root can log in using ssh(1). The argument must be ``yes'', ``without-password'', ``forced-commands-only'' or ``no''. The default is ``yes''.

If this option is set to ``without-password'' password authenti- cation is disabled for root.

If this option is set to ``forced-commands-only'' root login with public key authentication will be allowed, but only if the command option has been specified (which may be useful for taking remote backups even if root login is normally not allowed). All other authentication methods are disabled for root.

If this option is set to ``no'' root is not allowed to log in.

So you could use PermitRootLogin without-password for allowing private/public key authentication while disallowing password authentication; or maybe PermitRootLogin forced-commands-only to let you login as root but without interactive access.

The latter case requires you to edit authorized_keys file, to specify which command is enabled for the logging is user, like this:

command="rdiff-backup --server" ssh-rsa AAAAB3NzaC1y... (rest of key)

or even better, allow forced-commands-only root login only from specific ip address:

from="",command="/home/user/command/to/execute" ssh-rsa AAAAB3NzaC1y... (rest of key)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.