对管理员组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。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部