標籤:blog io os 使用 for 檔案 sp 2014 c
通常情況下,一般使用者通過執行“su -”命令、輸入正確的root密碼,可以登入狀態root使用者來對系統進行管理員層級的配置。
但是,為了更進一步加強系統的安全性,有必要建立一個管理員的 組,只允許這個組的使用者來執行“su -”命令登入狀態root使用者,而讓其他組的使用者即使執行“su -”、輸入了正確的root密碼,也無法登入狀態root使用者。在UNIX和Linux下,這個組的名稱通常為“wheel”。
一、禁止非whell組使用者切換到root
1、 修改/etc/pam.d/su配置
[[email protected] ~]# vi /etc/pam.d/su ← 開啟這個設定檔#auth required /lib/security/$ISA/pam_wheel.so use_uid ← 找到此行,去掉行首的“#”
2、 修改/etc/login.defs檔案
[[email protected] ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs ← 添加語句到行末以上操作完成後,可以再建立一個新使用者,然後用這個建立的使用者測試會發現,沒有加入到wheel組的使用者,執行“su -”命令,即使輸入了正確的root密碼,也無法登入狀態root使用者
3、 添加一個使用者woo,測試是否可以切換到root
[[email protected] ~]# useradd woo[[email protected] ~]# passwd wooChanging password for user woo.New UNIX password: BAD PASSWORD: it is WAY too shortRetype new UNIX password: passwd: all authentication tokens updated successfull
4、通過woo使用者登入嘗試切換到root
[[email protected] ~]$ su - root ← 即使密碼輸入正確也無法切換Password: su: incorrect password[[email protected] ~]$
5: 把root使用者加入wheel組再嘗試切換,可以切換
[[email protected] ~]# usermod -G wheel woo ← 將普通使用者woo加在Administrator 群組wheel組中[[email protected] ~]# su - woo[[email protected] ~]$ su - root ← 這時候我們看到是可以切換了 Password: [[email protected] ~]#
二、添加使用者到管理員,禁止普通使用者su到root
6、添加使用者,並加入Administrator 群組,禁止普通使用者su到root,以配合之後安裝OpenSSH/OpenSSL提升遠端管理安全
[[email protected] ~]# useradd admin[[email protected] ~]# passwd adminChanging password for user admin.New UNIX password: BAD PASSWORD: it is too shortRetype new UNIX password: passwd: all authentication tokens updated successfully.[[email protected] ~]# usermod -G wheel admin (usermod -G wheel admin 或 usermod -G10 admin(10是wheel組的ID號))[[email protected] ~]# su - admin[[email protected] ~]$ su - rootPassword: [[email protected] ~]#
方法一:wheel組也可指定為其它組,編輯/etc/pam.d/su添加如下兩行
[[email protected] ~]# vi /etc/pam.d/suauth sufficient /lib/security/pam_rootok.so debugauth required /lib/security/pam_wheel.so group=wheel
方法二:編輯/etc/pam.d/su將如下行#符號去掉
[[email protected] ~]# vi /etc/pam.d/su#RedHat#auth required /lib/security/$ISA/pam_wheel.so use_uid ← 找到此行,去掉行首的“#”#CentOS5#auth required pam_wheel.so use_uid ← 找到此行,去掉行首的“#”
#儲存退出即可============
[[email protected] ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs ← 添加語句到行末
(實際測試這步操作可省略)
Linux禁止非WHEEL使用者使用SU命令