【前情】

远程服务器使用的是AutoDL平台,其特点是基于Linux与SSH连接。需求来自于在连接了远程服务器的VS Code中登录Codex时,出现“Token  exchange failed: token endpoint returned status 403 Forbidde”报错。其原因是:远程服务器不能连接OpenAI。

操作步骤

1、对齐颗粒度

①AutoDL 端:申请并开启服务器

②VS Code 端:通过autodl提供的SSH密码连接远程服务器

③VPN 端:开启VPN,在“设置”中查看代理端口号<A>

2、修改本地SSH配置

①本地的SSH配置位于:

C:\Users\<用户名>\.ssh\config

②打开文件后,追加:

RemoteForward <A> 127.0.0.1:<A>

并记录下<Host>、<Port>和<User>。

3、修改AutoDL代理环境配置

在VS Code中已经连接好远程服务器的终端输入并执行:

cat >> /root/.bashrc <<'EOF'

export HTTP_PROXY="http://127.0.0.1:<A>"
export HTTPS_PROXY="http://127.0.0.1:<A>"
export http_proxy="http://127.0.0.1:<A>"
export https_proxy="http://127.0.0.1:<A>"

export NO_PROXY="127.0.0.1,localhost"
export no_proxy="127.0.0.1,localhost"

EOF

source /root/.bashrc

4、VS Code远端配置

Shift+Ctrl+P ---> 打开远程设置 ---> 修改为如下内容:

{
    "http.proxy": "http://127.0.0.1:<A>",
    "http.proxySupport": "on",
    "terminal.integrated.env.linux": {
        "HTTP_PROXY": "http://127.0.0.1:<A>",
        "HTTPS_PROXY": "http://127.0.0.1:<A>",
        "http_proxy": "http://127.0.0.1:<A>",
        "https_proxy": "http://127.0.0.1:<A>",
        "NO_PROXY": "127.0.0.1,localhost",
        "no_proxy": "127.0.0.1,localhost"
    }
}

5、复制本地Codex的授权文件

scp -P <Port> \
"$HOME\.codex\auth.json" \
<User>@<Host>:~/.codex/auth.json

6、重新连接远程服务器就OK啦~(●'◡'●)

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐