我知道以前经常问这个问题,但是我无法使其正常工作。
我想关闭系统而不用用户holmer
输入密码
我添加了以下行
holmer ALL=(ALL:ALL) NOPASSWD: /sbin/shutdown /usr/bin/timedatectl /usr/sbin/reboot
从sudo visudo
到/etc/sudoers
。
这实际上是文件/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
# Disable sudo password for shutdown and timedatectl for user holmer
holmer ALL=(ALL) NOPASSWD: /sbin/shutdown /usr/bin/timedatectl /usr/sbin/reboot
我还尝试将带有该行的文件添加到/etd/sudoers.d/
。 -也没有用。
如果我取消注释行#
的{{1}},则会收到错误消息。
操作系统:Ubuntu 20.04
答案 0 :(得分:1)
sudoers文件中的命令应以逗号分隔。试试这个:
holmer ALL=(ALL) NOPASSWD:/sbin/shutdown,/usr/bin/timedatectl,/usr/sbin/reboot