对管理员组wheel的管理

在CentOS中管理员组是wheel组,只有该组的成员才可以通过su -命令来切换为root(在ubuntu中管理组为admin)。

  1. 启用wheel管理员组

vim /etc/pam.d/su

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# 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

将auth required pam_wheel.so use_uid这行去掉注释。
vim + /etc/login.defs 在最后添加如下内容:

SU_WHEEL_ONLY yes

修改su的权限(可选)

chgrp wheel /bin/su
chmod 4750 /bin/su
  1. 新建普通用户加入wheel组
useradd cerana
usermod -a -G wheel cerana
查看用户组
id 或者 groups

不在wheel管理员组中的用户就无法通过su -切换到root了。
不在wheel管理员组中的用户同时也无法通过su切换至其他普通用户。

  1. 如何让wheel组的成员可以su到root,或者su到其他用户,而非wheel组成员只能su到非root用户?

vim /etc/pam.d/su 中添加

auth [ignore=1 default=ignore] pam_wheel.so use_uid debug
auth required pam_listfile.so item=user sense=deny onerr=succeed file=/etc/sudeny
  • 在未使用 trust 选项时,若用户属于 wheel 组,返回值是 PAM_IGNORE,对应的在 control flag 中的 value 是 ignore。其中 ignore = 1 表示返回值为 PAM_IGNORE 时,跳过后面的 1 条规则, 而 default=ignore 表示如果返回了其他没有指定 action 的 value,则忽略此规则。

  • 使用 pam_listfile.so 模块,检查 /etc/sudeny 文件(由参数 file=/etc/sudeny 指定)。如果不存在该文件或其他诸如不能读取的错误发生,将返回 PAM_SUCCESS(由参数 onerr=succeed 指定)。如果存在,读取 /etc/sudeny 文件的内容进行用户名检查(由参数 item=user 指定)。文件中指定的用户(由参数 sense=deny 限定)是不能成为su的对象的。然后,将 root 写入 /etc/sudeny 文件即可。

  • 可以参考man pam_wheel。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值