Linux学习笔记之CentOS7的 wheel组

  • Wheel源自俚语big wheel,意味大人物。该组的用户,可以通过输入密码或不输入密码的方式提权为root
  • Wheel组是Unix系统一个遗留物, 如今大多数的Linux发行版本中,仍然保留了wheel这个组,虽然它已经不像当初设计出来的那样必要了
  • wheel组的目的是不让不属于该组的用户通过 su 切换到 root, 即便知道root密码
  • wheel的权利来自 /etc/sudoers 中的 %wheel ALL=(ALL) ALL 这句
  • Ubuntu 没有wheel组

加入wheel组的方法

  1. 用 useradd 创建用户并加入
# 用户的主组被设为wheel
useradd -g wheel 用户名

# 用户的附加组添加wheel组
useradd -G wheel 用户名

-g只能一个组,且设为主组 -G可以多个组,用逗号分隔

  1. 用 usermod
# 只加-G(--groups)不加-a(--append)会移出该用户原先的附加组, 不会移出主组
usermod -G wheel 用户名  

# -aG 等同 -a(--append) -G(--groups) , 加上 -a 后 就不会移出原先的附加组了
usermod -aG wheel 用户名  

# -aG 等同 -a(--append) -G(--groups) , 加上 -a 后 就不会移出原先的附加组了
useradd -a -G wheel 用户名  
  1. 用 gpasswd
gpasswd -a 用户名 wheel

gpasswd -M 用户名 wheel
  1. 修改 /etc/group 文件
sudo vi /etc/group

wheel: x:10: 后添加用户名 , 以逗号分隔



移出wheel组的方法

  • 方法1
sudo gpasswd -d 用户名 wheel
  • 方法2 修改 /etc/group 文件
sudo vi /etc/group

wheel: x:10: 后去除用户名




/etc/pam.d/su

在 /etc/pam.d/su 中, 与wheel有关的有两句 , 默认是加注释的,
此时所有用户能su到root, 要密码

#%PAM-1.0
auth            sufficient      pam_rootok.so

# 取消注释以下行以隐式信任“wheel”组中的用户。(就是 su 不用输入密码)
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid  //这句

## 取消下面这行的注释, 则要求使用su的用户必须在"wheel"组中
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required        pam_wheel.so use_uid        //和这句

auth            substack        system-auth
auth            include         postlogin
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         include         postlogin
session         optional        pam_xauth.so

启用这条👇使得wheel成员su到root不用输密码

auth           sufficient      pam_wheel.so trust use_uid

启用这条👇使得非wheel成员无法切换到root

auth           required        pam_wheel.so use_uid

wheel为何牛? 来自 /etc/sudoers

wheel组的能力来自 /etc/sudoers 里的 %wheel ALL=(ALL) ALL 这句

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

也可以自定义超级组

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL
%SuperGroup  ALL=(ALL)       ALL

秘籍

使 wheel 组用户 su 时, 不用输入密码

去掉 /etc/pam.d/su 文件的 #auth sufficient pam_wheel.so trust use_uid //这句的注释(井号#)

使 wheel 组用户 sudo 时, 不用输入密码

去掉 /etc/sudoers 文件的 # %wheel ALL=(ALL) NOPASSWD: ALL //这句的注释(井号#)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐