Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 know in /etc/sudoers, one can put Defaults rootpw, but then sudo asks for the root password for all commands. Is there any way I can have sudo ask for the root password for some commands and the user password for others?

share|improve this question
up vote 5 down vote accepted

Defaults can be set for everything or for certain Hosts, Users or Commands

man sudoers says :

Defaults Certain configuration options may be changed from their default values at runtime via one or more Default_Entry lines. These may affect all users on any host, all users on a specific host, a specific user, a specific command, or commands being run as a specific user. Note that per-command entries may not include command line arguments. If you need to specify arguments, define a Cmnd_Alias and reference that instead.

    Default_Type ::= 'Defaults' |
                     'Defaults' '@' Host_List |
                     'Defaults' ':' User_List |
                     'Defaults' '!' Cmnd_List |
                     'Defaults' '>' Runas_List

So try :

Defaults!cmdlist rootpw
share|improve this answer

You can turn turn off root password for specific commands and specific users by adding this line to /etc/sudoers:

username1 hostname1 =NOPASSWD: /usr/bin/command_name1,/usr/bin/command_name2
username2 hostname2 =NOPASSWD: /usr/bin/command_name1,/usr/bin/command_name2
share|improve this answer

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.