内容 / 向导 / SSH 硬化

SSH 硬化 最少8分钟

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

相关