Sudoers文件,为用户启用NOPASSWD,所有命令
前言
这是一个与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 alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL nicholsonjf ALL=NOPASSWD: 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
但是,这不起作用,每当我运行’nicholsonjf’命令时,我仍然会提示输入密码。 一旦我从sudo和admin组中删除’nicholsonjf’,我才能开始以’nicholsonjf’开始运行sudo命令。
谁能解释为什么这有效?
是因为用户’nicholsonjf’inheritance了’admin’和’sudo’两个组规范中的sudo权限(在下面的sudoers文件中看到),它们覆盖了’nicholsonjf’用户规范,因为它们在配置文件?
您添加的行已被覆盖。 从man sudoers
:
当多个条目与用户匹配时,它们将按顺序应用。 如果有多个匹配项,则使用最后一个匹配项(不一定是最具体的匹配项)。
在你的情况下, nicholsonjf
是sudo
组的成员,所以对他来说这行适用:
%sudo ALL=(ALL:ALL) ALL
如果要覆盖/etc/sudoers
条目,只需将新条目放在它们之后。
新条目看起来应该是这样的
myuser ALL=(ALL) NOPASSWD:ALL
对于单个用户,或
%sudo ALL=(ALL) NOPASSWD:ALL
一组的%sudo ALL=(ALL) NOPASSWD:ALL
。
对于单个用户:
superuser ALL=(ALL) NOPASSWD:ALL
对于一个团体:
%supergroup ALL=(ALL) NOPASSWD:ALL
正如Vince 在评论中提到的那样 ,你可以使用这一行:
%sudo ALL=NOPASSWD: ALL
(这与那些 答案中显示的行不同,它解决了我的问题。)