I'm trying to make sudo ask for target password, except when run by root. Here's what I do:

Defaults:!root    targetpw

This way it asks for my password, and if I make it like this:

Defaults:yuri    targetpw

it asks for target user's password, but that's not what I wanted.

  • 2
    Doesn't just Defaults targetpw do the job? – Mikel Apr 4 '14 at 15:57
  • @Mikel Well, it appears yes, but I wonder what's wrong with Defaults:!root. – x-yuri Apr 4 '14 at 16:35

All you can do is set targetpw as default, but this won't require root to enter any password. You can't configure sudo to do this and it wouldn't make any sense, either, since root may always do whatever he wants (su doesn't ask for a password either, does it‽).

So put

Defaults targetpw

into your /etc/sudoers file and you should have su behavior.

  • Any clues what's wrong with Defaults:!root? – x-yuri Apr 4 '14 at 16:38
  • Tried to figure it out, but… no. – Andreas Wiese Apr 4 '14 at 16:43

From the sudoers man page:

An exclamation point (‘!’) can be used as a logical not operator in a list or
alias as well as in front of a Cmnd.  This allows one to exclude certain values.
For the ‘!’ operator to be effective, there must be something for it to exclude.
For example, to match all users except for root one would use:


 If the ALL, is omitted, as in:


 it would explicitly deny root but not match any other users.  This is different
 from a true “negation” operator.


Defaults:ALL,!root    targetpw

should be what you are looking for.

  • Thanks, that's the only thing that made me uncomfortable about the issue, but I accepted Andreas Wiese's answer, because it seems more like it for the task. – x-yuri Apr 4 '14 at 17:05

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.