Registrati Accedi
n/tothost-vn · 13 min fa · 24 visualizzazioni
u/TothostCommerciante verificatoArgentoMerchant verificato
n/tothost-vnu/Tothost Merchant verificato · 13 min fa

[教程] 新VPS到手后必做的安全初始化(Debian/Ubuntu)

新 VPS 开通后,公网 IP 往往几分钟内就会被扫描、尝试爆破 SSH。下面是一套适用于 Debian 11/12、Ubuntu 22.04/24.04 的基础初始化流程,按顺序做完大约 10 分钟。

⚠️ 操作前请确认可以通过服务商的 VNC / 控制台登录,万一 SSH 配置出错还能救回来。

1. 更新系统

apt update && apt upgrade -y

2. 创建普通用户并授予 sudo

adduser deploy
usermod -aG sudo deploy

deploy 可以换成你自己的用户名。

3. 配置 SSH 密钥登录

在本地电脑生成密钥(已有可跳过):

ssh-keygen -t ed25519 -C "my-vps"

把公钥上传到 VPS:

ssh-copy-id deploy@你的IP

Windows 没有 ssh-copy-id 的话,可以手动把本地 ~/.ssh/id_ed25519.pub 的内容追加到 VPS 上的 /home/deploy/.ssh/authorized_keys。

👉 先新开一个终端,确认能用密钥登录,再进行下一步。

4. 关闭密码登录和 root 直接登录

sudo nano /etc/ssh/sshd_config

修改 / 确认以下几项:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

注意:部分系统在 /etc/ssh/sshd_config.d/ 下还有配置文件(例如云镜像的 50-cloud-init.conf),可能会覆盖上面的设置,记得一起检查:

sudo grep -r "PasswordAuthentication" /etc/ssh/sshd_config.d/

检查语法并重启 SSH(Debian/Ubuntu 的服务名是 ssh):

sudo sshd -t && sudo systemctl restart ssh

5. 启用防火墙 UFW

sudo apt install ufw -y
sudo ufw allow 22/tcp          # 如果改过 SSH 端口,这里换成新端口
sudo ufw allow 80,443/tcp      # 需要建站时再开
sudo ufw enable
sudo ufw status

6. 安装 Fail2ban 防爆破

sudo apt install fail2ban -y
sudo tee /etc/fail2ban/jail.local > /dev/null <<'EOF'
[sshd]
enabled  = true
backend  = systemd
maxretry = 5
findtime = 10m
bantime  = 1h
EOF
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

backend = systemd 是为了兼容 Debian 12 这类默认不生成 /var/log/auth.log 的系统。

7. 开启 BBR(可选,改善跨境 / 高延迟线路的 TCP 吞吐)

echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
sysctl net.ipv4.tcp_congestion_control

输出 bbr 即成功。需要内核 4.9+(Debian 10+ / Ubuntu 18.04+ 默认满足),并且是 KVM、VMware 等完整虚拟化,OpenVZ / LXC 容器通常无法自行修改。

8. 时区与自动安全更新(可选)

sudo timedatectl set-timezone Asia/Shanghai
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure -plow unattended-upgrades

✅ 检查清单

  • 系统已更新
  • 已创建普通用户并加入 sudo
  • 密钥登录正常,已禁用密码登录与 root 登录
  • UFW 已启用,SSH 端口已放行
  • Fail2ban 正常运行
  • BBR 已开启(可选)

以上步骤在 TotHost 越南 VPS(TOT K 为 KVM 架构、TOT M 为 VMware 架构)上都可以直接使用。想先测试线路可以用我们的 Looking Glass:https://lg.tothost.vn/ ,有问题欢迎在评论区或 Telegram 群 https://t.me/tothostvietnam 交流。

2
3
Accedi per partecipare alla discussione.
u/udc2b6nr Annuncio
QuicksilverVPN

快银 VPN,一键连接全球节点,线路稳定、延迟低。支持 Windows、macOS 等多平台,TUN 全局模式覆盖全部应用流量。无需复杂配置,下载即用。

umami.dnsl.top Scopri di più

3 risposte

Ordinamento
  1. rewadi Bronzo 9 min fa

    thanks

    0
  2. chenchunmiao Bronzo 7 min fa

    收藏

    0
  3. James 💯 Leggenda MANAGER 6 min fa

    好帖,感谢分享。

    0