Visudo NOPASSWD 无法在特定文件上运行

Visudo NOPASSWD 无法在特定文件上运行

我试图排除我编写的一个脚本在执行时询问密码,即使它包含“sudo”命令

所以我通过 visudo 编辑了 sudoers,添加

myuser  ALL=(ALL) NOPASSWD: /home/script.sh

但是当我执行它时它仍然要求输入 sudo 密码,
我试图设置一个更广泛的规则,例如

myuser ALL=(ALL) NOPASSWD: ALL

它可以工作,但这不是我想要的,我只希望该命令不要要求我输入密码

这是我的 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

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

# User privilege specification
root    ALL=(ALL:ALL) ALL
myuser  ALL=(ALL) NOPASSWD: /home/script.sh

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

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

#includedir /etc/sudoers.d

相关内容