linux su 拒绝权限,Linux禁止非WHEEL用户使用su命令

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 ← 添加语句到行末

(实际测试这步操作可省略)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值