任何公开的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步吗? 我们的服务器船默认变硬了... 见计划.