1. Ubuntu 开启 SSH
bash
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh
systemctl status ssh
hostname -I
确认 SSH 状态为 active (running),记录 Ubuntu 的局域网 IP。若启用了 UFW:
bash
sudo ufw allow ssh
2. Windows 连接 Ubuntu
在 Windows PowerShell 中执行:
powershell
ssh Ubuntu用户名@Ubuntu_IP
例如:
powershell
ssh jack@192.168.1.105
若连接失败,可检查 Ubuntu 的 SSH 端口:
bash
sudo ss -tlnp | grep :22
并在 Windows 测试:
powershell
Test-NetConnection 192.168.1.105 -Port 22
3. 建立 SSH 反向端口转发
假设 Windows 上的 HTTP 代理监听在 127.0.0.1:7890。在 Windows PowerShell 中执行:
powershell
ssh -N -R 7890:127.0.0.1:7890 jack@192.168.1.105
保持该 SSH 窗口运行。隧道建立后,Ubuntu 上的 127.0.0.1:7890 会转发到 Windows 的 127.0.0.1:7890。
4. 在 Ubuntu 测试代理
bash
curl -x http://127.0.0.1:7890 https://api.openai.com
也可以测试:
bash
curl -x http://127.0.0.1:7890 https://www.google.com
5. Pi Coding Agent 使用代理
启动 Pi 时设置代理环境变量:
bash
HTTPS_PROXY=http://127.0.0.1:7890 \
HTTP_PROXY=http://127.0.0.1:7890 \
pi
如果只希望某个 provider 使用代理,可在 provider 配置中指定 proxy:
json
{
"providers": [
{
"name": "overseas",
"baseUrl": "https://api.example.com/v1",
"apiKey": "$MY_API_KEY",
"proxy": "http://127.0.0.1:7890",
"models": ["my-model"]
}
]
}
这样可为指定 provider 配置代理;未单独设置时,可使用 HTTP_PROXY 和 HTTPS_PROXY 环境变量。
参考文档: