Sudoers and defaults

sudosudoedit

I need to allow to a user to run passwordless sudo without tty.

I have a file under /etc/sudoers.d/ with the special commands and settings I need, since I don't fancy editing directly the sudoers file. In that file I have the following:

# My list of commands that the user can run passwordless
myUser ALL=(ALL) NOPASSWD:SETENV: /foo/bar /foo/zaz
# My new defaults.
Defaults exempt_group = myUser
Defaults !env_reset,env_delete-=PATH
Defaults: myUser !requiretty

However when I su to the user and run sudo -l I get this in the defaults:

 Matching Defaults entries for myUseron this host:
    requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION
    LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin, exempt_group=myUser,
    !env_reset, env_delete-=PATH, !requiretty

Where I can see it has first requiretty and in the end my !requiretty, which does not work.
I assume this is happening because it is first parsed the normal sudoers file, then my custom file under /etc/sudoers.d/.

Is there a way of making this work without editing the original /etc/sudoers?

Best Answer

The grammar for the Defaults is this (see man sudoers):

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

User_List ::= User |
              User ',' User_List

So on line

Defaults: myUser !requiretty

remove the space between Defaults: and myUser.

Related Question