MaxAuthTries
限制bash
# /etc/ssh/sshd_config 配置
PermitRootLogin no
PermitEmptyPasswords no
PasswordAuthentication no # 推荐使用密钥认证
使用密钥认证替代密码认证
ssh-keygen -t ed25519
ssh-copy-id user@host
更改默认SSH端口
# /etc/ssh/sshd_config
Port 2222 # 或其他非标准端口
限制访问IP
# /etc/ssh/sshd_config
AllowUsers user@192.168.1.*
启用双因素认证
定期审计
# 检查认证日志
grep 'Failed password' /var/log/auth.log
# 检查异常登录
last
如果发现SSH被入侵: 1. 立即断开受影响服务器网络 2. 检查/var/log/auth.log等日志 3. 检查~/.ssh/authorized_keys是否有异常密钥 4. 重置所有用户密码 5. 审查所有用户账户 6. 更新所有系统软件
请记住,安全是一个持续的过程,需要定期审查和更新安全措施。