指南

10 分钟内保护新 VPS

初学者10분 읽기업데이트됨 2026년 6월 18일
간단한 답변

五个更改就能消除几乎所有的自动化攻击:基于密钥的 SSH(禁用密码)、禁止直接 root 登录、默认拒绝防火墙(同时覆盖 IPv4 和 IPv6)、自动安全更新以及 fail2ban。它们一起大约需要十分钟,并且比任何提供商功能都重要。

01 生成并安装 SSH 密钥

Do this from your own machine, not the server. Ed25519 keys are shorter and faster than RSA and are supported everywhere that matters.

ssh-keygen -t ed25519 -C "onionvps-$(date +%Y%m)"
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@YOUR_SERVER_IP

02 创建非 root 用户

Working as root all the time removes a useful safety net and makes every mistake maximally expensive.

adduser --gecos "" ops
usermod -aG sudo ops
rsync --archive --chown=ops:ops ~/.ssh /home/ops

03 加固 SSH 守护进程

Disable password authentication entirely — brute force against key-only SSH is not possible. Keep a second terminal connected while you do this, so a mistake does not lock you out.

cat >/etc/ssh/sshd_config.d/99-hardening.conf <<'EOF'
PasswordAuthentication no
PermitRootLogin no
KbdInteractiveAuthentication no
AllowUsers ops
EOF
sshd -t && systemctl reload ssh

04 设置默认拒绝防火墙

Cover IPv6 as well as IPv4. Every OnionVPS instance has a routed /64, so a v4-only ruleset leaves every service publicly reachable over v6.

ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80,443/tcp
ufw enable
ufw status verbose   # confirm IPv6 shows as enabled

05 开启自动安全更新

Unattended upgrades close the window between a patch being published and you noticing it exists.

apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades

06 安装 fail2ban 并拍摄快照

fail2ban mostly reduces log noise once passwords are disabled, but it is cheap. Then snapshot the configured state — that becomes your known-good baseline.

apt install -y fail2ban && systemctl enable --now fail2ban

자주 묻는 질문

我应该更改 SSH 端口吗?

这是减少噪音而不是安全,但它是有效的噪音减少——绝大多数扫描器只尝试 22 端口。结合仅密钥认证,无论如何残余风险都可以忽略不计。

如果我把自己锁在门外怎么办?

使用控制面板中的带外 VNC 控制台。它连接到虚拟串行控制台,并且完全无需网络即可工作。