SSH 安全加固与密钥登录实践¶
SSH 暴露在公网时,最常见的威胁不是“被破解”,而是“被撞库 + 弱口令 + 扫描爆破”。
1. 推荐的 sshd 配置(示例)¶
/etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 60
ClientAliveCountMax 2
2. 配合防火墙/Fail2ban¶
- 只允许管理网段访问 22
- 用 fail2ban 对爆破来源临时封禁
3. 密钥与权限¶
- 私钥妥善保管,必要时加 passphrase
~/.ssh/authorized_keys权限正确(chmod 600)