Why is Sudoers NOPASSWD Option Applying to ROOT Instead of Specified User?

19.04i3-wmpermissionssudo

/etc/sudoers:

# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

h ALL=NOPASSWD: /usr/bin/brightlight -i 20 -f /sys/class/backlight/amdgpu_bl0

But doing the command still gives me a permission error.

h@pop-os:~$ brightlight -i 20 -f /sys/class/backlight/amdgpu_bl0
brightlight: could not open "brightness" file: Permission denied

Also

h@pop-os:~$ sudo -l
Matching Defaults entries for h on pop-os:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User h may run the following commands on pop-os:
    (ALL : ALL) ALL
    (root) NOPASSWD: /usr/bin/brightlight -i 20 -f /sys/class/backlight/amdgpu_bl0

Things I have tried:

  • Rebooting
  • Creating a file in /etc/sudoers.d/brightlight with last line of config above

EDIT: Fixed, you need to add sudo, and it won't prompt you for a password

Best Answer

Your entry in /etc/sudoers means that you can run

sudo brightlight -i 20 -f /sys/class/backlight/amdgpu_bl0

without being asked for a password. It doesn't mean you can run

brightlight -i 20 -f /sys/class/backlight/amdgpu_bl0

without sudo.