任何 VPS 的最小安全配置:仅用 SSH 密钥、防火墙、fail2ban 与自动安全更新。真实命令。
任何公网 VPS 上线几分钟内就会遭到暴力破解。这是阻止它的基本防线。适用于任何 Ubuntu/Debian 服务器:包括我们的。
# 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!
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config systemctl reload ssh # keep this session open; test a NEW connection before closing it
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
apt install -y unattended-upgrades dpkg-reconfigure -plow unattended-upgrades # choose Yes
这就是服务器安全的 80/20 原则:密钥、防火墙、封禁、补丁。想跳过第 1–2 步?我们的服务器默认已做过加固:查看套餐。