Linux 安全检查脚本_linux安全测试工具

https://www.cisecurity.org/benchmark/centos_linux

参考以上链接的CentOS 安全基线内容,选择自用的检查项。如下,有列出密码长度的手动显示方式。

Audit:
Verify password creation requirements conform to organization policy.
Run the following command to verify the minimum password length is 14 or more
characters.

# grep '^\s*minlen\s*' /etc/security/pwquality.conf
minlen = 14

建立一个.sh脚本文件,并增加可执行权限,用有root权限的账户运行脚本。

参考脚本如下(基本检查项可根据需求增加)

#!/bin/bash
main() {
echo " 脚本检查结果" 
local pw_len=0

# 检查login.defs中的密码长度设置
if [ -f "/etc/login.defs" ]; then
pw_len=$(grep "^PASS_MIN_LEN" /etc/login.defs | awk '{print $2}')
if [ -n "$pw_len" ]; then
echo "/etc/login.defs 密码最小长度: $min_len" |
else
echo "警告: /etc/login.defs 未设置PASS_MIN_LEN" 
fi
fi

# 密码长度是否符合要求
if [ "$min_len" -ge 12 ]; then
echo "符合安全标准: 系统密码最小长度 ≥ 12 位"
elif [ "$min_len" -ge 8 ]; then
echo "警告: 密码长度基本合格但建议12位以上" 
elif [ "$min_len" -gt 0 ]; then
echo "严重: 密码长度不足! "
else
echo "严重: 系统未配置密码最小长度要求!" 
fi

# 密码复杂度要求
grep -q "ucredit=-.*[1-9]" /etc/pam.d/system-auth && \
grep -q "dcredit=-.*[1-9]" /etc/pam.d/system-auth && \
grep -q "ocredit=-.*[1-9]" /etc/pam.d/system-auth && \
grep -q "lcredit=-.*[1-9]" /etc/pam.d/system-auth
if [ $? -eq 0 ]; then
echo "符合安全标准: 已启用大小写、数字和特殊字符要求" 
else
echo "严重: 未启用密码复杂度要求" 
fi
echo *************************
echo -e "\n[+] 检查完成"
}
main
原文链接:,转发请注明来源!