`root ALL=(ALL:ALL) ALL` 和 `root ALL=(ALL) ALL` 之间有什么区别?

这行文字来自我的Ubuntu 14.04。
root    ALL=(ALL:ALL) ALL

第三个ALL的含义是什么?

上述行与root ALL=(ALL) ALL有何区别?

2个回答

虽然sudoers manpage可能有点令人生畏,但其中提供了一些示例来帮助澄清事情:
 dgb     boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm

Then user dgb is now allowed to run /bin/ls as operator, but /bin/kill and /usr/bin/lprm as root.

We can extend this to allow dgb to run /bin/ls with either the user or group set to operator:

 dgb     boulder = (operator : operator) /bin/ls, (root) /bin/kill,\
         /usr/bin/lprm
我们可以推断,给定一个形式为sudoers的行:
A B = (C:D) E

D指的是可以使用的组。

因此,第三个ALL表示用户可以在任何组下运行该命令。


如果使用 (ALL) 而不是 (ALL:ALL),那么该用户不能在那些命令中使用 sudo -g
Runas_Spec
  A Runas_Spec determines the user and/or the group that a command may 
  be run as.             ...  The second defines a list of groups that
  can be specified via `sudo`'s `-g` option.  If both Runas_Lists are
  specified, the command may be run with any combination of users and
  groups listed in their respective Runas_Lists. If only the first is
  specified, the command may be run as any user in the list but no `-g`
  option may be specified.

(上述例子来自同一部分。)

1在上面的例子中,有人可以帮助我理解什么是“boulder”吗? - Arun
2@Arun boulder是一个主机名。在大多数常见的情况下,你只需要使用ALL来匹配所有的主机。 - muru

发现了一个有趣的文档 root ALL=(ALL:ALL) ALL
- 第一个字段表示规则适用的用户名(root)。 - 第一个“ALL”表示此规则适用于所有主机。 - 第二个“ALL”表示root用户可以以所有用户身份运行命令。 - 第三个“ALL”表示root用户可以以所有组身份运行命令。 - 第四个“ALL”表示这些规则适用于所有命令。