为什么 sudoers 的 NOPASSWD 选项将例外应用于 ROOT 而不是指定用户?

为什么 sudoers 的 NOPASSWD 选项将例外应用于 ROOT 而不是指定用户?

/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

但是执行该命令仍然会出现权限错误。

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

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

我尝试过的事情:

  • 重启
  • /etc/sudoers.d/brightlight使用上面最后一行配置创建一个文件

编辑:已修复,您需要添加sudo,并且它不会提示您输入密码

答案1

您输入/etc/sudoers意味着您可以运行

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

无需输入密码。这并不意味着你可以运行

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

没有sudo

相关内容