在linux主机安全检查中有这么一项:限制su成root的用户或组。正常状况下,咱们使用普通用户管理设备和巡检,可是常常有一部分人员不断尝试su到root用户,若是尝试次数过多,root用户就会被临时锁定,为了不这种状况和提升安全性。咱们必须经过设置来禁止普通用户使用su命令切换到root用户。linux
1,编辑/etc/pam.d/suvim
将#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.defsbash
shift+G切换到最后一行,添加命令SU_WHEEL_ONLY yeside
vim /etc/login.defs # Use SHA512 to encrypt password. ENCRYPT_METHOD SHA512 SU_WHEEL_ONLY yes
这个时候,除了root用户以外,其余用户都不能使用su命令登陆到root用户,ui
[root@localhost ~]# su test01 [test01@localhost root]$ su - root 密码: su: 拒绝权限
3,将容许使用使用su的用户加入wheel组it
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用户组,实验效果:class
[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用户。test