0

我知道这个问题以前经常被问到,但我不可能让它发挥作用。

我想在不输入用户密码的情况下关闭系统holmer

holmer ALL=(ALL:ALL) NOPASSWD: /sbin/shutdown /usr/bin/timedatectl /usr/sbin/reboot 我在sudo visudoto中添加了以下行 /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/. - 它也没有奏效。如果我取消注释该##includedir /etc/sudoers.d,我会收到一条错误消息。

操作系统:Ubuntu 20.04

4

1 回答 1

2

sudoers 文件中的命令应以逗号分隔。尝试这个:

holmer ALL=(ALL) NOPASSWD:/sbin/shutdown,/usr/bin/timedatectl,/usr/sbin/reboot
于 2020-09-28T15:30:40.007 回答