为什么不能升级 OpenSSH?
在某些生产环境、老旧系统或受监管的系统中,直接升级 OpenSSH 可能带来兼容性问题、服务中断或违反合规要求。此时,需采取替代措施降低漏洞风险。
不升级情况下的缓解措施
- 限制 SSH 访问源:通过 iptables 或 firewalld 仅允许可信 IP 访问 22 端口。
- 禁用弱加密算法:在
/etc/ssh/sshd_config中关闭 CBC 模式、MD5、SHA1 等不安全算法。 - 关闭 root 登录:设置
PermitRootLogin no,强制使用普通用户 + sudo。 - 启用密钥认证,禁用密码登录:设置
PasswordAuthentication no提高安全性。 - 限制用户和组访问:使用
AllowUsers或AllowGroups控制谁能登录。 - 部署 Fail2Ban:自动封禁多次尝试失败的 IP,防止暴力破解。
- 监控与日志审计:定期检查
/var/log/secure或/var/log/auth.log异常登录行为。
示例:加固 sshd_config 配置片段
# /etc/ssh/sshd_config 安全建议
Protocol 2
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers alice bob
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
注意事项
以上方法仅为临时缓解手段,长期仍应规划 OpenSSH 升级路径。对于严重漏洞(如 CVE-2024-6387),若无法打补丁,建议隔离主机或迁移服务。