一、PAM簡單介紹
1.它提供了對所有服務進行認證的中央機制,適用於login,遠程登錄(telnet,rlogin,fsh,ftp,點對點協議(PPP)),su等應用程序中。系統管理員通過PAM配置文件來制定不同應用程序的不同認證策略;應用程序開發者通過在服務程序中使用PAM API(pam_xxxx( ))來實現對認證方法的調用;而PAM服務模塊的開發者則利用PAM SPI來編寫模塊(主要是引出一些函數pam_sm_xxxx( )供PAM接口庫調用),將不同的認證機制加入到系統中;PAM接口庫(libpam)則讀取配置文件,將應用程序和相應的PAM服務模塊聯系起來。

2.官網:http://www.linux-pam.org/
二、PAM相關文件
1.包名:pam

2.模塊文件目錄:
/usr/lib64/security/*.so

3.某些模塊的配置文件:
/etc/security/

4.每個應用模塊對應的配置文件:
/etc/pam.d/

三、PAM配置文件說明
1.專用配置文件/etc/pam.d/ 格式
type control module-path arguments
四列

2. 模塊類型(module-type)
- Auth 賬號的認證和授權
- Account 帳戶的有效性,與賬號管理相關的非認證類的功能,如:用來限制/允許用戶對某個服務 的訪問時間,限制用戶的位置(例如:root用戶只能從控制台登錄)
- Password 用戶修改密碼時密碼復雜度檢查機制等功能
- Session 用戶會話期間的控制,如:最多打開的文件數,最多的進程數等
- -type 表示因為缺失而不能加載的模塊將不記錄到系統日志,對於那些不總是安裝在系統上的模塊有用
3.Control:
- required :一票否決,表示本模塊必須返回成功才能通過認證,但是如果該模塊返回失敗,失敗結果也不會立即通知用戶,而是要等到同一type中的所有模塊全部執行完畢,再將失敗結果返回給應用程序,即為必要條件
- requisite :一票否決,該模塊必須返回成功才能通過認證,但是一旦該模塊返回失敗,將不再執行同一type內的任何模塊,而是直接將控制權返回給應用程序。是一個必要條件
- sufficient :一票通過,表明本模塊返回成功則通過身份認證的要求,不必再執行同一type內的其它模塊,但如果本模塊返回失敗可忽略,即為充分條件,優先於前面的required和requisite
- optional :表明本模塊是可選的,它的成功與否不會對身份認證起關鍵作用,其返回值一般被忽略
- include: 調用其他的配置文件中定義的配置信息
4.module-path:
- 模塊文件所在絕對路徑:
- 模塊文件所在相對路徑:/lib64/security目錄下的模塊可使用相對路徑,如:pam_shells.so、pam_limits.so
- 有些模塊有自已的專有配置文件,在/etc/security/*.conf目錄下
5.Arguments
- debug :該模塊應當用syslog( )將調試信息寫入到系統日志文件中
- no_warn :表明該模塊不應把警告信息發送給應用程序
- use_first_pass :該模塊不能提示用戶輸入密碼,只能從前一個模塊得到輸入密碼
- try_first_pass :該模塊首先用前一個模塊從用戶得到密碼,如果該密碼驗證不通過,再提示用戶輸入新密碼
- use_mapped_pass 該模塊不能提示用戶輸入密碼,而是使用映射過的密碼
- expose_account 允許該模塊顯示用戶的帳號名等信息,一般只能在安全的環境下使用,因為泄漏用戶名會對安全造成一定程度的威脅
四、Pam_shells模塊
功能:pam_shells is a PAM module that only allows access to the system if the user's shell is listed in /etc/shells.

五、pam_securetty.so模塊
功能:am_securetty is a PAM module that allows root logins only if the user is logging in on a "secure" tty, as defined by the listing in the securetty file. pam_securetty checks at first, if /etc/securetty exists. If not and it was built with vendordir support, it will use %vendordir%/securetty. pam_securetty also checks that the securetty files are plain files and not world writable. It will also allow root logins on the tty specified with console= switch on the kernel command line and on ttys from the /sys/class/tty/console/active.

centos8默認沒有這個文件
六、pam_nologin.so 模塊
功能:pam_nologin is a PAM module that prevents users from logging into the system when /var/run/nologin or /etc/nologin exists. The contents of the file are displayed to the user. The pam_nologin module has no effect on the root user's ability to log in.



寫於2022-3-21-17:03
