Linux禁止非WHEEL使用者使用SU命令

來源:互聯網
上載者:User

標籤:art   安裝   cat   code   uid   roo   openssl   su -   ati   

        通常情況下,一般使用者通過運行“su -”命令、輸入正確的rootpassword。能夠登入狀態root使用者來對系統進行管理員層級的配置。

       可是。為了更進一步加強系統的安全性,有必要建立一個管理員的 組,僅僅同意這個組的使用者來運行“su -”命令登入狀態root使用者。而讓其它組的使用者即使運行“su -”、輸入了正確的rootpassword,也無法登入狀態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 -”命令。即使輸入了正確的rootpassword,也無法登入狀態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命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.