新 VPS 交付后按本清单初始化,可挡掉绝大多数自动化攻击。
1. 更新系统并设置密码
apt update && apt upgrade -y
passwd
adduser ops && usermod -aG sudo ops
2. 加固 SSH
- 先配置密钥登录(见「使用 SSH 密钥登录 VPS」);
- 编辑
sshd_config设置PasswordAuthentication no; - 执行
systemctl restart sshd,新窗口验证能登录后再关旧会话。
3. 启用防火墙
ufw allow 22/tcp && ufw enable
只放行业务必需端口,其余拒绝。
4. 防护与校时
- 安装 fail2ban:
apt install fail2ban -y; - 设置时区:
timedatectl set-timezone Asia/Shanghai。
注意:调整 SSH 与防火墙时保持当前会话,另开窗口验证可用后再收尾。