购买 VPS 后你会拿到什么
一台位于数据中心的远程虚拟服务器,通常附带:公网 IP、操作系统(如 Ubuntu 24.04)、SSH 端口(22)、登录用户名(root 或 ubuntu)、密码或 SSH Key。
Skills · Private Network Infrastructure
从 SSH 到 Reality + VLESS:面板与命令行两种方式完整部署笔记。
一台位于数据中心的远程虚拟服务器,通常附带:公网 IP、操作系统(如 Ubuntu 24.04)、SSH 端口(22)、登录用户名(root 或 ubuntu)、密码或 SSH Key。
推荐组合是 SSH + SSH Key,不是 SSH + 密码。Key 更安全,可以彻底关闭密码登录,也可以为每台设备单独授权和撤销。
服务器保存公钥,本地电脑保存私钥。登录时本地用私钥签名,服务器用公钥验证——私钥本身永远不会发送给服务器。
商家可能没有提供下载文件,而是在网页上显示类似内容。复制时必须从 -----BEGIN ... PRIVATE KEY----- 开始,到 -----END ... PRIVATE KEY----- 结束,保留中间所有内容和换行,不要把网页上的说明文字一起复制。
mkdir -p ~/.sshchmod 700 ~/.sshnano ~/.ssh/my-vps-keychmod 600 ~/.ssh/my-vps-keyssh-keygen -y -f ~/.ssh/my-vps-keyctrl+o 保存,ctrl+x 退出 nano。验证应输出 ssh-ed25519 AAAAC3...,出现 invalid format 检查是否漏了 BEGIN/END 行。
Unix 权限三个数字依次:文件所有者、同组用户、其他用户。读=4,写=2,执行=1。数字可相加。
700 ~/.ssh 目录:只有我能进入600 private key / config:只有我能读写Mac 提示符:rda@MacBook ~ %。服务器:root@vps:~# 或 ubuntu@vps:~$。以 ubuntu 登录时需管理员权限加 sudo。
ssh -i ~/.ssh/my-vps-key root@你的服务器IPssh -i ~/.ssh/my-vps-key ubuntu@你的服务器IPssh -p 2222 -i ~/.ssh/my-vps-key ubuntu@IP首次连接提示 Are you sure... 输入 yes。
Host myvps
HostName 你的服务器IP
User root
Port 22
IdentityFile ~/.ssh/my-vps-key
IdentitiesOnly yeschmod 600 ~/.ssh/configssh myvps| SSH + 密码 | SSH + SSH Key | |
|---|---|---|
| 安全性 | 弱密码可能被猜中 | Ed25519 几乎不可能暴力破解 |
| 多设备 | 同密码 | 独立密钥,单独授权撤销 |
| 建议 | 不推荐公网使用 | 推荐,加 passphrase 双重保护 |
每台电脑生成独立密钥,不要复制同一份 private key。公钥保存在 ~/.ssh/authorized_keys。流程:商家密钥首次登录 → 各电脑 ssh-keygen → public key 加入 authorized_keys → 测试 → 确认后删除旧公钥。
chmod 600 ~/.ssh/my-vps-keyls -la ~/.sshssh-keygen -R 服务器IPsudo apt updatesudo apt upgrade -ysudo apt install -y curl openssl nanotimedatectl statussudo timedatectl set-ntp trueREALITY 对时间差敏感。
sudo ss -lntp | grep ':443 'sudo ufw allow OpenSSHsudo ufw allow 443/tcpsudo ufw enable
sudo ufw status务必先放行 SSH 再启用 UFW。云厂商安全组也要同步放行。
购买 VPS → SSH Key 登录 → 确认稳定 → 部署前准备 → 选面板或命令行 → 配置 Reality + VLESS → 客户端测试。
3x-ui 面板方式:Web 界面管理,自动生成分享链接,适合新手。
Xray 命令行方式:直接编辑 JSON 配置,更轻量。两种方式共享同一个 Xray-core 内核。
ssh root@IP 登录| 项目 | 官方地址 | 用途 |
|---|---|---|
| Xray-core | XTLS/Xray-core | 预编译内核 |
| Xray-install | XTLS/Xray-install | 命令行安装脚本 |
| 3x-ui | MHSanaei/3x-ui | Xray Web 面板 |
| 3x-ui Releases | MHSanaei/3x-ui Releases | 稳定版与更新日志 |
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)如果没有 curl,先执行 apt update && apt install -y curl。
services:
3xui:
image: ghcr.io/mhsanaei/3x-ui:latest
container_name: 3xui_app
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
- ./db/:/etc/x-ui/
- ./cert/:/root/cert/
environment:
XRAY_VMESS_AEAD_FORCED: "false"
XUI_ENABLE_FAIL2BAN: "true"
ports:
- "2053:2053"
- "443:443"
tty: true
restart: unless-stoppeddocker compose up -dNET_ADMIN 与 NET_RAW 用于让容器内 Fail2Ban 真正执行封禁;每个节点入站端口也必须加入 ports。默认 admin/admin,首次登录必须修改。
| 项目 | 建议 | 说明 |
|---|---|---|
| 面板端口 | 随机值或手动输入 | 登录后台用 |
| 用户名/密码 | 脚本生成随机值 | 不要用弱密码 |
| Web Base Path | 保留随机路径 | http://IP:端口/路径 |
| SSL 证书 | 有域名选 Let's Encrypt | 需 80 端口可用 |
| Bind 127.0.0.1 | 跳过 SSL 时选 y | 用 SSH 隧道访问 |
ssh -L 2222:127.0.0.1:面板端口 root@服务器IPbash <(curl -Ls https://gh-proxy.com/https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/ghcr.io/mhsanaei/3x-ui:latestx-uisystemctl status x-ui --no-pagerprintf 'y\n' | x-ui uninstallsystemctl stop x-ui 2>/dev/null
systemctl disable x-ui 2>/dev/null
rm -f /etc/systemd/system/x-ui.service /usr/bin/x-ui
rm -rf /etc/x-ui /usr/local/x-ui /var/log/x-ui
systemctl daemon-reload
systemctl reset-failedufw statusufw allow 22/tcp
ufw allow 面板端口/tcp
ufw allow 节点端口/tcp| 项目 | 建议值 | 说明 |
|---|---|---|
| Protocol | VLESS | |
| Port | 自定义 | 如 443、8443 |
| Transmission | TCP | |
| Security | Reality | 生成密钥对 |
| Flow | xtls-rprx-vision | 两端一致 |
| Dest / SNI | www.microsoft.com:443 | TLS 1.3 站点 |
| Public Key | 复制给客户端 | 不填 Private |
| Short ID | 生成值 | 两端一致 |
目标站点需真实存在、443 可访问、TLS 稳定。初学者用 www.microsoft.com:443。
/usr/local/bin/xray tls ping www.microsoft.comcurl -I --tlsv1.3 https://www.microsoft.com从服务器出口测试,优先选 TLS 握手快、状态码稳定的站点。
cat > /tmp/reality-target-test.sh <<'EOF'
#!/usr/bin/env bash
sites=(www.microsoft.com www.apple.com www.cloudflare.com www.amazon.com www.samsung.com www.nvidia.com www.intel.com www.oracle.com)
printf "%-24s %-6s %-8s %-8s %-8s %-8s\n" "SITE" "CODE" "DNS" "TCP" "TLS" "TOTAL"
for site in "${sites[@]}"; do
result=$(curl -o /dev/null -sS --connect-timeout 5 --max-time 10 --tlsv1.3 \
-w "%{http_code}|%{time_namelookup}|%{time_connect}|%{time_appconnect}|%{time_total}" \
"https://${site}" 2>/dev/null)
if [ $? -eq 0 ]; then
IFS='|' read -r code dns tcp tls total <<DATA
$result
DATA
printf "%-24s %-6s %-8s %-8s %-8s %-8s\n" "$site" "$code" "$dns" "$tcp" "$tls" "$total"
else
printf "%-24s failed\n" "$site"
fi
done
EOFbash /tmp/reality-target-test.sh| 客户端字段 | 填写内容 |
|---|---|
| Address | VPS 公网 IP |
| Port | 入站端口,如 443 |
| UUID | 服务器 VLESS UUID |
| Encryption | none |
| Transport | tcp |
| Security | reality |
| Flow | xtls-rprx-vision |
| SNI | 同服务端 |
| Fingerprint | chrome |
| Public Key | x25519 客户端值——绝不能 PrivateKey |
| Short ID | 同服务端 |
| SpiderX | / 或留空 |
vless://UUID@VPS_IP:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.microsoft.com&fp=chrome&pbk=PublicKey&sid=ShortID&type=tcp&headerType=none#VPSpbk 填客户端 PublicKey——绝不能填 PrivateKey。
面板端口用于登录后台;节点端口才是客户端连接端口。填错表现为连接失败。
手动填写容易漏掉 Flow、Public Key 或 Short ID。首选 3x-ui 生成的分享链接。
直接安装 Xray-core 并用 JSON 配置管理。更轻量,也更容易理解每一步在做什么。
安装 Xray-core
使用 XTLS 官方安装脚本
生成密钥
UUID、x25519 与 Short ID
编辑 config.json
填入参数、目标站与 SNI
测试配置
运行 xray run -test
启动与验证
重启服务并测试客户端
sudo bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install/usr/local/bin/xray version路径:/usr/local/bin/xray,配置 /usr/local/etc/xray/config.json。
/usr/local/bin/xray uuid/usr/local/bin/xray x25519openssl rand -hex 8xray x25519 输出 PrivateKey 和 Password(或 PublicKey)。PrivateKey → 服务器,Password/PublicKey → 客户端。
替换 UUID、PrivateKey、ShortID 三个占位符。RAW 传输在 streamSettings 中使用 "network": "raw"。
{
"log": { "loglevel": "warning" },
"inbounds": [{
"tag": "vless-reality-in",
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [{ "id": "UUID", "flow": "xtls-rprx-vision" }],
"decryption": "none"
},
"streamSettings": {
"network": "raw",
"security": "reality",
"realitySettings": {
"show": false,
"target": "www.microsoft.com:443",
"serverNames": ["www.microsoft.com"],
"privateKey": "PrivateKey",
"shortIds": ["ShortID"]
}
},
"sniffing": { "enabled": true, "destOverride": ["http","tls","quic"] }
}],
"outbounds": [
{ "tag": "direct", "protocol": "freedom" },
{ "tag": "blocked", "protocol": "blackhole" }
]
}sudo /usr/local/bin/xray run -test -config /usr/local/etc/xray/config.jsonsudo systemctl restart xray
sudo systemctl enable xraysudo systemctl status xray --no-pagersudo ss -lntp | grep ':443 'sudo journalctl -u xray -fsudo journalctl -u xray -n 100 --no-pager客户端连接后访问 https://ipinfo.io,显示 VPS IP 即为生效。同时在服务器:
sudo journalctl -u xray -ftimedatectl)systemctl status x-ui --no-pagerjournalctl -u x-ui -n 80 --no-pagerss -lntp | grep -E '面板端口|节点端口'nc -vz 服务器IP 节点端口nc -vz 服务器IP 面板端口timedatectl)任何影响 SSH 的修改都保留一个已登录窗口作为退路。