1、修改文件/etc/pam.d/su
root@ *node* @node3:/root# cat /etc/pam.d/su
#%PAM-1.0
authsufficientpam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#authsufficientpam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
authrequiredpam_wheel.so use_uid #取消注释
authsubstacksystem-auth
authincludepostlogin
accountsufficientpam_succeed_if.so uid = 0 use_uid quiet
accountincludesystem-auth
passwordincludesystem-auth
sessionincludesystem-auth
sessionincludepostlogin
sessionoptionalpam_xauth.so
2、修改文件/etc/login.defs
root@ *node* @node3:/root# cat /etc/login.defs
。。。。
SU_WHEEL_ONLY yes #最后一行添加
3、测试
root@ *node* @node3:/root# su - web
上一次登录:五 8月 2 17:54:08 CST 2019pts/2 上
[web@node3 ~]$ su - root
密码:
su: 拒绝权限
[web@node3 ~]$
4、添加用户到wheel组测试
root@ *node* @node3:/root# vim /etc/group
....
wheel:x:10:web #多个用户逗号隔开
....
root@ *node* @node3:/root# su - web
上一次登录:五 8月 2 17:59:38 CST 2019pts/2 上
[web@node3 ~]$ su - root
密码:
上一次登录:五 8月 2 17:54:39 CST 2019pts/2 上
最后一次失败的登录:五 8月 2 17:59:45 CST 2019pts/2 上
最有一次成功登录后有 1 次失败的登录尝试。
方法一:wheel组也可指定为其它组,编辑/etc/pam.d/su添加如下两行
[root@ ~]# vi /etc/pam.d/su
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel
方法二:编辑/etc/pam.d/su将如下行#符号去掉
[root@ ~]# vi /etc/pam.d/su
#RedHat#auth required /lib/security/$ISA/pam_wheel.so use_uid ← 找到此行,去掉行首的“#”
#CentOS5#auth required pam_wheel.so use_uid ← 找到此行,去掉行首的“#”
#保存退出即可============
[root@ ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs ← 添加语句到行末
(实际测试这步操作可省略)