![当一个组没有密码时,对多个组中的用户使用 sudo 要求输入密码](https://linux22.com/image/619348/%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BB%84%E6%B2%A1%E6%9C%89%E5%AF%86%E7%A0%81%E6%97%B6%EF%BC%8C%E5%AF%B9%E5%A4%9A%E4%B8%AA%E7%BB%84%E4%B8%AD%E7%9A%84%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%20sudo%20%E8%A6%81%E6%B1%82%E8%BE%93%E5%85%A5%E5%AF%86%E7%A0%81.png)
所以我有一个用户正在运行 sudo,他们同时在 wheel 和 other_group 中。other_group 不需要密码,但 wheel 需要。我的问题是:wheel 要求 sudo 密码是否否定了 other_group 不需要密码的事实?
以下是运行中的片段sudo visudo
:
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
%other_group ALL=(ALL) NOPASSWD: ALL
答案1
通常情况下,最后一场比赛获胜。来自 sudoers 手册页
当多个条目与用户匹配时,将按顺序应用它们。如果有多个匹配项,则使用最后一个匹配项(不一定是最具体的匹配项)。
您是否绝对确定该用户属于这两个组?
在 Centos 系统上,我必须按预期工作
%wheel ALL=(ALL) ALL
%other_group ALL=(ALL) NOPASSWD: ALL
不需要密码,因为 other_group 在 wheel 之后。
%other_group ALL=(ALL) NOPASSWD: ALL
%wheel ALL=(ALL) ALL
由于 wheel 位于 other_group 之后,因此要求输入密码。