/etc/pam.d/su
是Linux系統中與用戶切換(su命令)相關的PAM(Pluggable Authentication Modules,可插拔認證模塊)配置文件。以下是對它的詳細介紹:
簡介
作用
PAM
是一種用于管理系統認證的機制,它允許系統管理員靈活地配置不同服務的認證方式和策略。/etc/pam.d/su
文件專門用于定義當用戶使用su
命令切換用戶身份時的認證規則和流程。例如,它可以指定是否允許無密碼切換、限制某些用戶的切換權限等。
配置文件內容示例
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth include system-auth
account include system-auth
password include system-auth
session include system-auth
配置項解釋
auth
:用于配置認證相關的參數。pam_rootok.so
:表示允許 root 用戶直接切換,無需密碼驗證。pam_wheel.so
:與用戶組“wheel”相關,trust use_uid
表示信任“wheel”組中的用戶,允許他們無需密碼切換;use_uid
則表示根據用戶的UID來進行權限判斷。include system-auth
:表示包含/etc/pam.d/system-auth
文件中的認證配置,這是一種復用通用認證配置的方式。
account
、password
、session
:分別用于配置賬戶相關、密碼相關和會話相關的參數,這里通過include system-auth
復用了系統的通用配置。
通過修改/etc/pam.d/su
文件,可以根據系統的安全需求和管理策略,靈活調整用戶切換身份的認證方式和權限控制。但需要注意的是,對該文件的修改需要謹慎操作,以免影響系統的正常運行和安全性。
實踐
利用admin_user 免密登錄切換用戶user01:user02:user03:user04:user05
cat /etc/pam.d/su
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
# 允許 agent_mgr 免密切換到指定用戶
#auth [success=1 default=ignore] pam_listfile.so item=user sense=allow file=/etc/security/su-agent_mgr onerr=fail
#auth sufficient pam_permit.soauth [success=ignore default=1] pam_succeed_if.so user in user01:user02:user03:user04:user05
auth sufficient pam_succeed_if.so use_uid user = admin_userauth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so