禁止普通用戶使用su命令切換到root用戶

 

 在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

相關文章
相關標籤/搜索