使用密钥,禁用密码
确认密钥可以正常登录后,新建一个 drop-in 配置文件,而不是直接修改主配置文件:
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
MaxAuthTries 3$ sshd -t && systemctl reload ssh # "sshd" on AlmaLinux/Rocky保持当前会话不要关闭,先在另一个终端中测试能否正常登录,确认无误后再关闭当前会话。万一出了问题,您仍可以通过 KVM 控制台登录。
防火墙
$ apt install ufw
$ ufw allow 22/tcp
$ ufw allow 443/tcp
$ ufw enable自动安全更新
$ apt install unattended-upgrades
$ dpkg-reconfigure -plow unattended-upgrades如果必须为其他服务保留密码登录,请加装 fail2ban。




