Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 3 down vote accepted

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.

share|improve this answer
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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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