使用 SSH 连接远程服务器时 Codex 出现 403 错误的解决方案

一、问题背景 你的目标是: 在 Windows + VSCode + Remote SSH + 远程 Linux 服务器 环境中让远程服务器能够正常使用 Codex / OpenAI API。 但遇到了两个问题: 1️⃣ 远程服务器访问 OpenAI 被限制(403 Country not supported)2️⃣ OAuth 登录回调 localhost 失败(ERR_CONNECTION_REFUSED) 解决思路: 用 SSH 反向隧道让远程服务器走本地代理 用 VSCode Port Forward解决 OAuth 回调 二、本机开启代理 先确保你本机有可用代理。 你的代理端口是: 127.0.0.1:9674 验证代理是否可用: PowerShell: $env:HTTP_PROXY="http://127.0.0.1:9674" $env:HTTPS_PROXY="http://127.0.0.1:9674" curl.exe -I https://api.openai.com 如果返回: HTTP/1.1 200 Connection established 说明代理正常。 三、建立 SSH 反向代理隧道 目的: 让远程服务器的流量通过 你的本地代理 出网。 执行: ssh -N -T -R 18080:127.0.0.1:9674 haoli@10.87.235.31 含义: ...

March 1, 2026 · 2 min · 296 words · Hao

WSL2 在开启 Windows 代理情况下安装 Codex CLI 的完整步骤

本文档提供两种方法在 WSL2 中使用 Windows 代理,并完成 Codex CLI 安装与登录。 方法一:通过 Windows 主机 IP 使用代理(适用于默认 NAT 网络) 步骤一:确认 Windows 代理端口 在 Windows PowerShell 或 CMD 执行 reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer 输出示例 ProxyServer REG_SZ 127.0.0.1:9674 说明 Windows 系统代理地址为 127.0.0.1:9674 步骤二:获取 Windows 在 WSL 网络中的 IP 进入 WSL 终端执行 grep nameserver /etc/resolv.conf 输出示例 nameserver 172.20.128.1 其中 172.20.128.1 为 Windows 主机在 WSL 网络中的地址。 步骤三:在 WSL 设置代理 在 WSL 终端执行 export http_proxy=http://172.20.128.1:9674 export https_proxy=http://172.20.128.1:9674 export HTTP_PROXY=http://172.20.128.1:9674 export HTTPS_PROXY=http://172.20.128.1:9674 步骤四:测试代理 执行 ...

February 1, 2026 · 2 min · 253 words · Hao

Linux 服务器配置 SSH 连接 GitLab 仓库

目标:让 Linux 服务器通过 SSH 访问公司 GitLab 仓库(免密码 clone / push)。 核心流程只有 4 步: 1️⃣ 生成 SSH key2️⃣ 把公钥添加到 GitLab 3️⃣ 测试 SSH 连接4️⃣ 使用 SSH clone ⭐ 一、在 Linux 服务器生成 SSH 密钥 推荐 ed25519(更安全、更快) ssh-keygen -t ed25519 -C "your_email" 一路回车即可。 生成后默认文件: ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub ⭐ 二、查看公钥内容 cat ~/.ssh/id_ed25519.pub 复制整行输出。 ⭐ 三、把公钥添加到 GitLab 进入 GitLab: 头像 → Preferences → SSH Keys 或直接: https://gitlab.xxx.com/-/profile/keys 粘贴公钥 → Add key。 ⭐ 四、测试 SSH 连接 ssh -T git@gitlab.xxx.com 第一次会提示: Are you sure you want to continue connecting? 输入: ...

June 1, 2025 · 2 min · 223 words · Hao