SSH 加固:8 分钟保护你的 VPS

任何 VPS 的最小安全配置:仅用 SSH 密钥、防火墙、fail2ban 与自动安全更新。真实命令。

任何公网 VPS 上线几分钟内就会遭到暴力破解。这是阻止它的基本防线。适用于任何 Ubuntu/Debian 服务器:包括我们的。

1. 先配置密钥(千万别把自己锁在门外)

# on YOUR computer:
ssh-keygen -t ed25519 -C "vps"
ssh-copy-id root@YOUR_SERVER_IP
ssh root@YOUR_SERVER_IP        # must log in WITHOUT password - verify!

2. 禁用密码登录

sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl reload ssh
# keep this session open; test a NEW connection before closing it

3. 防火墙与防暴力破解

apt install -y ufw fail2ban
ufw default deny incoming && ufw default allow outgoing
ufw allow OpenSSH && ufw enable
cat > /etc/fail2ban/jail.local <<'EOF'
[sshd]
enabled = true
maxretry = 5
bantime = 1h
EOF
systemctl enable --now fail2ban

4. 自动安全更新

apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades   # choose Yes

这就是服务器安全的 80/20 原则:密钥、防火墙、封禁、补丁。想跳过第 1–2 步?我们的服务器默认已做过加固:查看套餐。

相关内容

查看套餐指南常见问题