这是一个与 sudoers 文件和 sudo 命令相关的相当复杂的问题。
注意:我在运行 Ubuntu Desktop 13.04 的专用机器上进行了这些更改,我仅将其用于学习目的。我知道启用 NOPASSWD sudo 会带来巨大的安全风险。
最初,我对 sudoers 文件 ( /etc/sudoers) 的唯一更改是一行,该用户规范应该使 nicholsonjf 能够使用 sudo 运行所有命令而无需输入密码(请参阅以 nicholsonjf 开头的行):
# 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"
# Host …Run Code Online (Sandbox Code Playgroud) 14.04 在这里。我通过 SSH 连接到我的机器,将以下行添加到/etc/sudoers:
myuser ALL=NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)
然后尝试运行:
sudo mkdir /etc/blah
Run Code Online (Sandbox Code Playgroud)
...我被要求输入密码。为什么?!?
我不希望这样的操作时,要问我的密码。请注意,当我运行时,ls -ltr /我得到:
drwxr-xr-x 94 root root 4096 Jul 30 13:28 etc
Run Code Online (Sandbox Code Playgroud)
但是我认为这并不重要,因为我已经将自己设置为“sudoer”,对吗?
更重要的是,我需要做什么才能以sudo mkdir /etc/blah当前用户 ( myuser) 的身份运行而不会被要求输入密码?
这是我的整个/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 …Run Code Online (Sandbox Code Playgroud) 我一直试图在没有密码的情况下授予www-data使用sudo service apache2 restart权限,但无论我尝试什么,都无济于事。我在不同的论坛上阅读了数百篇关于这个问题的帖子,但没有任何帮助。
我知道权限是按顺序添加的,所以特定的命令应该放在列表的末尾。这是我的文件:
#
# 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 secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
# Members of …Run Code Online (Sandbox Code Playgroud) 我正在尝试为NOPASSWD属于该sudo组并具有管理员权限的现有用户添加选项。我在sudoers文件中添加了这一行:
max ALL=(ALL:ALL) NOPASSWD: ALL
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用sudo.