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

Dri*_*leX 8 sudo

这一行来自我的 Ubuntu 14.04

root    ALL=(ALL:ALL) ALL
Run Code Online (Sandbox Code Playgroud)

第三个是什么意思ALL

上面那行和 有root ALL=(ALL) ALL什么区别?

mur*_*uru 9

虽然sudoers联机帮助页可能有点令人兴奋,但给出的示例有助于澄清问题:

 dgb     boulder = (operator) /bin/ls, (root) /bin/kill, /usr/bin/lprm
Run Code Online (Sandbox Code Playgroud)

然后用户dgb现在被允许运行/bin/lsas operator, but/bin/kill/usr/bin/lprmas root

我们可以扩展这个允许dgb运行/bin/ls与用户或组设置为operator

 dgb     boulder = (operator : operator) /bin/ls, (root) /bin/kill,\
         /usr/bin/lprm
Run Code Online (Sandbox Code Playgroud)

我们可以推断出,给定sudoers一行形式:

A B = (C:D) E
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

(以上示例来自同一部分。)

  • @Arun `boulder` 是一个主机名。在当今最常见的情况下,您只需使用“ALL”来匹配所有主机。 (2认同)

Aru*_*run 5

发现一个有趣的文档

\n

根全部=(全部:全部)全部

\n
    \n
  • 第一个字段表示规则将应用于
    \n(root) 的用户名。

    \n
  • \n
  • 第一个\xe2\x80\x9cALL\xe2\x80\x9d表示该规则适用于所有主机。

    \n
  • \n
  • 第二个 \xe2\x80\x9cALL\xe2\x80\x9d 表示 root 用户可以以所有
    用户身份运行命令。

    \n
  • \n
  • 第三个 \xe2\x80\x9cALL\xe2\x80\x9d 表示 root 用户可以作为所有
    组运行命令。

    \n
  • \n
  • 第四 \xe2\x80\x9cALL\xe2\x80\x9d 表示这些规则适用于所有命令。

    \n
  • \n
\n