# 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
gauri ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown
答案1
您的线路gauri ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown
应该已经正常工作,允许用户在无需 的情况下重新启动sudo
。您的问题在于您将其放置在哪里。
如果你看看sudoers
手册页因为#includedir
,你会看到为什么:
包括/etc/sudoers.local
当 sudo 到达此行时,它将暂停处理当前文件 (/etc/sudoers) 并切换到 /etc/sudoers.local。
就你的情况而言,是这样的/etc/sudoers.d
,但同样的概念也适用。你需要将行移动gauri ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown
到部分上方#includedir
,如下所示:
# 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
# Allow user gauri to execute reboot without sudo
gauri ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d