3

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

2 Answers 2

4

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.

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

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:

     ALL,!root

 If the ALL, is omitted, as in:

     !root

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

So,

Defaults:ALL,!root    targetpw

should be what you are looking for.

1
  • 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, 2014 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .