在linux主机安全检查中有这么一项:限制su成root的用户或组。正常情况下,我们使用普通用户管理设备和巡检,但是经常有一部分人员不断尝试su到root用户,如果尝试次数过多,root用户就会被临时锁定,为了避免这种情况和提高安全性。我们必须通过设置来禁止普通用户使用su命令切换到root用户。


1,编辑/etc/pam.d/su

将#auth     required       pam_wheel.so ues_uid这行注释取消

vim /etc/pad.d/su
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid

2,编辑vi /etc/login.defs

shift+G切换到最后一行,添加命令SU_WHEEL_ONLY yes

vim /etc/login.defs
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
SU_WHEEL_ONLY yes

  这个时候,除了root用户之外,其他用户都不能使用su命令登录到root用户,

[root@localhost ~]# su test01
[test01@localhost root]$ su - root
密码:
su: 拒绝权限

3,将允许使用使用su的用户加入wheel组

usermod -G wheel test
查看test用户gid
[root@localhost ~]# id test
uid=1001(test) gid=1001(test) 组=1001(test),10(wheel)

  我们使用test用户和test01两个用户做实验,test用户加入到wheel用户组,test01没有加入到wheel用户组,实验效果:

[root@localhost ~]# su test01
[test01@localhost root]$ su - root
密码:
su: 拒绝权限                             
[test01@localhost root]$ exit
exit
[root@localhost ~]# su test
[test@localhost root]$ su - root
密码:
[root@localhost ~]#

  没有加入到wheel组的test01不能切换到root用户,加入到wheel组的test用户可以切换到root用户。