组 root 和组 sudo 有什么区别?为什么 root 用户默认不是 sudo 组的成员?

ran*_*cho 2 root sudo user-management visudo groups

我对这个问题很困惑。

据我所知,用户 root 拥有所有特权。

此外,组 sudo 的所有用户都拥有所有特权。

但默认情况下,用户 root 不是组 sudo 的成员。那么root用户怎么可能是sudo用户呢?

请向我解释整个概念。

请注意,下面提到的命令会产生下面提到的输出:

$root@lenovo:/home/rancho# compgen -u
-----
-----
root
rancho
-----
-----
$root@lenovo:/home/rancho# compgen -g
-----
-----
root
rancho
sudo
-----
-----
$root@lenovo:/home/rancho# getent group sudo
sudo:x:27:rancho
$root@lenovo:/home/rancho# getent group root
root:x:0
$root@lenovo:/home/rancho# visudo
#
# 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        rootpw
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

# 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

:x
$root@lenovo:/home/rancho#
Run Code Online (Sandbox Code Playgroud)

wja*_*rea 5

您说root拥有所有特权是正确的,但是说sudoers拥有所有特权并不完全正确。他们可以通过使用sudoroot身份运行命令来获得所有权限。这包括使用像sudo -i.

root不是sudoer,因为它已经是root - 它不需要成为root来运行命令。