Ubuntu SSH的安全加固可以通过以下步骤进行:
ssh-keygen命令生成公私钥对,推荐使用ed25519密钥类型,因为它提供了更高的安全性和性能。ssh-keygen -t ed25519 -a 256 -c "your_email@example.com"
~/.ssh/authorized_keys文件中,确保每个私钥占据一行。ssh-copy-id user@remote_host
/etc/ssh/sshd_config文件中设置PermitRootLogin no,禁止root用户直接登录。PasswordAuthentication no,禁用密码认证,推荐使用密钥认证。MaxAuthTries来限制失败的认证尝试次数,防止暴力破解。MaxStartups限制并发的未认证连接,防止DoS攻击。sudo ufw allow 2222/tcp
sudo ufw enable
apt-get安装Fail2Ban,配置它来防止暴力破解攻击。sudo apt-get install fail2ban
sudo cp /etc/fail2ban/jail.local /etc/fail2ban/jail.local.local
sudo apt update && sudo apt upgrade
logwatch或fail2ban监控系统日志,及时发现异常行为。通过上述步骤,可以显著提高Ubuntu SSH服务的安全性,保护系统和数据不受未经授权的访问和攻击。