
问题Password age is 99999Default account SSH login is not disabled.Public key authentication is not enabled.Password age is 99999 问题这是主要设置Linux用户密码过期天数将默认值99999改成90天即可sed-is/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90//etc/login.defs这里主要就是将/etc/login.defs将默认99999天改成90天还需要对已有用户进行更改# 查询出所有用户的用户名awk-F:$3 1000 $1 ! nobody {print $1}/etc/passwd chage-M90$用户名检查sudochage-l$用户名Default account SSH login is not disabled.禁止默认用户使用SSH远程登录。创建一个ssh配置文件sudovim/etc/ssh/sshd_config.d/deny-default-user.conf添加内容DenyUsers ec2-user这需要重启sshsystemctl restart sshd检查sudosshd-T|grepdenyusersPublic key authentication is not enabled.这里是需要显示启用私钥文件登录。即sed-is/#PubkeyAuthentication yes/PubkeyAuthentication yes//etc/ssh/sshd_config需要重启sshsystemctl restart sshd检查sudosshd-T|greppubkeyauthenticationEB管理EC2.ebextensions/00security-ec2.configfiles:# 1. 直接在 sshd_config.d 目录下创建模块化配置文件/etc/ssh/sshd_config.d/deny-default-user.conf:mode:000644owner:rootgroup:rootcontent:|DenyUsers ec2-usercommands:# 1. 修改全局默认配置确保未来创建的所有用户都遵循 90 天过期限制00_update_login_defs:command:sed -i s/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/ /etc/login.defs01_pubkey_authentication_yes:command:sed -i s/#PubkeyAuthentication yes/PubkeyAuthentication yes/ /etc/ssh/sshd_config02_update_pass_max_days:command:|# 获取所有 UID 大于等于 1000 的普通用户并设置密码最长有效期为 90 天 for user in $(awk -F: $3 1000 $1 ! nobody {print $1} /etc/passwd); do chage -M 90 $user done# 2. 检查 SSH 语法并重启服务03_restart_sshd:# 使用 sshd -t 检查刚创建的配置是否合法合法则重启command:systemctl restart sshd总结主要就是一下常见的linux系统安全管理。用EB来管理EC2可以把一下常见的运维配置都搞到CI/CD工作流的配置代码里面来。以后这运维也可以让代码接管。参考passwdsshdPASS_MAX_DAYS