# 在本机(192.168.247.197)上启动
./setup_remote_copilot.sh
{
"http.proxyStrictSSL": false,
"http.systemCertificates": false,
"Lingma.HttpProxySettings": "manual",
"Lingma.HttpProxyConfigurationURL": "http://172.16.40.16:7280",
"http.proxy": "http://localhost:7280",
"http.proxySupport": "on",
"github.copilot.enable": {
"*": true,
"yaml": true,
"plaintext": true,
"markdown": true
},
"github.copilot.advanced": {
"debug.overrideEngine": "codex",
"debug.useNodeFetcher": true
},
"http.proxyAuthorization": null
}
ssh -L 8082:localhost:8101 10.192.72.11
就可以在本机(192.168.247.197)通过访问 http://localhost:8082 来访问远程服务了。
ssh -o "ExitOnForwardFailure=yes" -o "ServerAliveInterval=60" -o "ServerAliveCountMax=3" -L 8082:localhost:8101 -R 7280:localhost:7890 ubuntu@10.192.72.11
ssh -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -L 8082:localhost:8101 -R 7280:localhost:7890 -N ubuntu@10.192.72.11
这个 SSH 命令用于建立隧道连接,让您可以从本地访问远程服务器上的服务,同时为远程服务器提供代理访问。这正好可以解决您 ngrok 连接问题。
让我详细解释这个命令的各个参数:
连接选项 (-o)
ExitOnForwardFailure=yes: 如果端口转发失败,立即退出 SSH 连接ServerAliveInterval=60: 每 60 秒发送一次保活信号ServerAliveCountMax=3: 最多发送 3 次保活信号无响应后断开连接-L 8082:localhost:8101: 本地端口转发
localhost:8082 相当于访问远程服务器的 localhost:8101-R 7280:localhost:7890: 远程端口转发
localhost:7280 相当于访问您本地的 localhost:7890-R 参数的完整格式
-R [bind_address:]port:host:hostport
hostport: 本机的目标端口
ssh -i /Users/zhch158/.ssh/id_dotsocr_tunnel -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -L 8082:localhost:8101 -R 7280:localhost:7281 -N ubuntu@10.192.72.11
这个 SSH 命令是您安全隧道方案的核心,让我详细解释每个参数的作用:
ssh -i /Users/zhch158/.ssh/id_dotsocr_tunnel \
-o ExitOnForwardFailure=yes \
-o ServerAliveInterval=30 \
-o ServerAliveCountMax=3 \
-L 8082:localhost:8101 \
-R 7280:localhost:7281 \
-N ubuntu@10.192.72.11
-i /Users/zhch158/.ssh/id_dotsocr_tunnel
~/.ssh/id_rsa 或其他默认密钥-o)ExitOnForwardFailure=yes
ServerAliveInterval=30
ServerAliveCountMax=3
-L)-L 8082:localhost:8101
localhost:8082 → 远程服务器的 localhost:8101http://localhost:8082 就相当于访问远程服务器的 vLLM 服务-R)-R 7280:localhost:7281
localhost:7280 → 您本机的 localhost:7281-N
ubuntu@10.192.72.11
您的 Mac (192.168.247.197) 远程服务器 (10.192.72.11)
┌─────────────────────────┐ ┌─────────────────────────┐
│ │ │ │
│ 🌐 浏览器 │ │ 🤖 vLLM 服务 │
│ localhost:8082 ◄───────┼─────────┼──► localhost:8101 │
│ │ SSH │ │
│ 🔒 安全代理服务器 │ 隧道 │ 其他用户进程 │
│ localhost:7281 ◄───────┼─────────┼──► localhost:7280 │
│ │ │ │ │ │
│ ▼ │ │ ▼ │
│ 🎯 本地代理 │ │ ❌ 被拒绝 │
│ localhost:7890 │ │ (安全检查失败) │
│ (Clash/V2Ray等) │ │ │
└─────────────────────────┘ └─────────────────────────┘
# secure_tunnel.py 中的配置
{
"local_forward_port": 8082, # 对应 -L 8082:localhost:8101
"remote_service_port": 8101, # 远程 vLLM 服务端口
"secure_proxy_port": 7281, # 对应 -R 7280:localhost:7281
"target_proxy_host": "127.0.0.1",
"target_proxy_port": 7890 # 最终的代理目标
}
localhost:7280localhost:7281localhost:7890(您的真实代理)# 远程服务器上的 vLLM 进程请求代理
curl http://localhost:7280/some-api
# 流程:
# 1. 请求到达远程服务器的 7280 端口
# 2. SSH 隧道转发到您本机的 7281 端口
# 3. 安全代理检测到 VS Code 进程运行 ✅
# 4. 转发请求到本机的 7890 端口(真实代理)
# 5. 返回响应
# 其他用户在远程服务器执行
curl http://localhost:7280/some-api
# 流程:
# 1. 请求到达远程服务器的 7280 端口
# 2. SSH 隧道转发到您本机的 7281 端口
# 3. 安全代理检测:没有 VS Code 进程 ❌
# 4. 返回 HTTP 403 Forbidden
# 5. 记录访问日志
这个命令实现了一个双向安全隧道:
🔍 验证监听状态 连接到远程主机后,可以检查端口监听状态:
# 检查监听端口
netstat -tlnp | grep 7280
# 或
ss -tlnp | grep 7280
# 应该看到类似输出:
# tcp 0 0 127.0.0.1:7280 0.0.0.0:* LISTEN # localhost 监听
# tcp 0 0 0.0.0.0:7280 0.0.0.0:* LISTEN # 所有接口监听
# tcp 0 0 10.192.72.11:7280 0.0.0.0:* LISTEN # 特定IP监听
sudo pkill -u ubuntu -f vscode
🛡️ 安全建议 默认使用 localhost:最安全,只有本机用户可访问 避免使用 0.0.0.0:除非确实需要外部访问 使用特定 IP:如果需要内网访问,指定具体的内网 IP 监控访问日志:定期检查谁在使用代理服务