天天看點

PAM和賬戶安全配置

  PAM(可插入認證子產品)是UNIX系統上一個實作子產品化的身份驗證子產品服務

當程式需要對使用者進行身份驗證時加載并執行的。PAM檔案通常位于/etc/pam.d目錄中。

配置檔案

/etc/pam.d/password-auth

/etc/pam.d/system-auth

/etc/security/pwquality.conf

配置密碼建立要求

編輯/etc/pam.d/password-auth和/etc/pam.d/system-auth,确定檔案含有

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=      

編輯密碼強度配置檔案/etc/security/pwquality.conf

minlen = 14
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1      
  • minlen = 14 -  密碼最小長度
  • ucredit = -1 - 必須包含一個大寫字元
  • ocredit = -1 - 必須包含一個特殊字元
  • lcredit = -1 -必須包含一個小寫字元
確定配置了失敗密碼嘗試的鎖定

在n次不成功的連續登入嘗試後鎖定使用者ID可減輕暴力對系統的密碼攻擊

檢視 ’/etc/pam.d/password-auth‘ 和 ’/etc/pam.d/system-auth‘檔案

并确認 pam_faillock.so 周圍有 pam_unix.so    pam_unix.so 是 [success=1 default=bad]

auth required pam_faillock.so preauth audit silent deny=5 unlock_time=900
auth [success=1 default=bad] pam_unix.so
auth [default=die] pam_faillock.so authfail audit deny=5 unlock_time=900
auth sufficient pam_faillock.so authsucc audit deny=5 unlock_time=900      

限制密碼重用次數

編輯/etc/pam.d/password-auth 和 /etc/pam.d/system-auth

password required pam_pwhistory.so remember=5      

确定密碼的加密算法 SHA-512

password    sufficient    pam_unix.so     sha512      

確定對su指令的通路受到限制

編輯/etc/pam.d/su

auth required pam_wheel.so use_uid      

編輯/etc/group

将允許的使用者加入wheel組,這裡以root和redhat使用者為例

wheel:x:10:root,redhat      

賬戶安全設定

  • /etc/login.defs

檢視賬戶過期時間和其它資訊

[root@frog ~]# chage -l redhat 
Last password change                    : Jun 11, 2020
Password expires                    : never
Password inactive                    : never
Account expires                        : never
Minimum number of days between password change        : 0
Maximum number of days between password change        : 99999
Number of days of warning before password expires    : 7      

確定系統賬戶是non-login

檢測腳本

egrep -v "^\+" /etc/passwd | awk -F: '($1!="root" && $1!="sync" &&
$1!="shutdown" && $1!="halt" && $3<1000 && $7!="/sbin/nologin" &&
$7!="/bin/false") {print}'      

修改為不允許登入

usermod -s /sbin/nologin <user>      

腳本批量設定

uid的小于1000除開root使用者,進行鎖定,除開一些特殊使用者,其它的都禁止登入。

#!/bin/bash
for user in `awk -F: '($3 < 1000) {print $1 }' /etc/passwd` ; do
 if [ $user != "root" ]; then
     usermod -L $user
     if [ $user != "sync" ] && [ $user != "shutdown" ] && [ $user != "halt" ];then
        usermod -s /sbin/nologin $user
     fi
 fi
done      

繼續閱讀