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
-
-
ucredit = -1 - 必须包含一个大写字符
-
ocredit = -1 - 必须包含一个特殊字符
-
确保配置了失败密码尝试的锁定
在n次不成功的连续登录尝试后锁定用户ID可减轻暴力对系统的密码攻击
确认 pam_faillock.so 周围有 pam_unix.so
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
password required pam_pwhistory.so remember=5
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
[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