Skip to content

zenggs05/vscode-remote-ssh-proxy-codex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

GitHub stars GitHub forks License VSCode OpenAI

VS Code Remote SSH Proxy for Codex/OpenAI

# 🚀 VS Code Remote SSH 代理配置全指南(解决 Codex / OpenAI 无法登录问题)

✅ 适用于:公司/学校服务器无法访问外网

✅ 一步打通:VS Code Remote SSH + 本地代理

✅ 支持:Codex / OpenAI / 扩展联网问题

---

# 📌 目录(TOC)

* [📖 背景与问题](#-背景与问题)

* [🧠 原理讲解(必须理解)](#-原理讲解必须理解)

* [🔧 配置步骤](#-配置步骤)

* [1️⃣ 确认本地代理端口](#1️⃣-确认本地代理端口)

* [2️⃣ SSH 反向端口转发](#2️⃣-ssh-反向端口转发)

* [3️⃣ 同步 Codex 登录信息](#3️⃣-同步-codex-登录信息)

* [4️⃣ 远程环境变量](#4️⃣-远程环境变量)

* [5️⃣ VS Code Remote 设置](#5️⃣-vs-code-remote-设置)

* [🧪 验证是否成功](#-验证是否成功)

* [❌ 常见错误](#-常见错误)

* [🎯 总结](#-总结)

* [🔍 SEO关键词](#-seo关键词)

---

# 📖 背景与问题

在以下场景中,你一定遇到过:

* VS Code Remote SSH 可以连接服务器

* 但 Codex / OpenAI 扩展无法登录 ❌

* 扩展市场打不开 ❌

* API 请求失败 ❌

👉 原因:

**远程服务器无法访问外网**

虽然 VS Code 在本地运行,但扩展运行在远程。

---

# 🧠 原理讲解(必须理解)

核心思想:

👉 **让远程服务器“借用”本地代理**

---

## 🌐 网络链路图(关键)

graph LR

A\[远程服务器 Codex扩展] --> B\[127.0.0.1:yyyy]

B --> C\[SSH反向端口转发]

C --> D\[本地 127.0.0.1:xxxx]

D --> E\[本地代理软件]

E --> F\[OpenAI API]

Loading

---

## 📌 参数说明

| 参数 | 含义 |

| ---- | -------------- |

| xxxx | 本地代理端口(如 7890) |

| yyyy | 远程映射端口(自定义) |

---

# 🔧 配置步骤

---

## 1️⃣ 确认本地代理端口

以 Clash 为例:

* ✅ HTTP Port:7890

* ❌ API Port:9090(不要用)

---

## 2️⃣ SSH 反向端口转发

编辑:

\~/.ssh/config

添加:


Host myserver

    HostName 你的服务器IP

    User 用户名

    RemoteForward 12345 127.0.0.1:7890

---

## 3️⃣ 同步 Codex 登录信息

本地:

tar -cf codex.tar \~/.codex

scp codex.tar user@server:\~/

远程:

tar -xf codex.tar -C \~/

---

## 4️⃣ 远程环境变量

export http\_proxy=http://127.0.0.1:12345

export https\_proxy=http://127.0.0.1:12345

export HTTP\_PROXY=http://127.0.0.1:12345

export HTTPS\_PROXY=http://127.0.0.1:12345

👉 写入 .bashrc 持久化

---

## 5️⃣ VS Code Remote 设置(关键)

打开:

Ctrl + Shift + P

输入:

Open Remote Settings (JSON)

添加:

{

  "http.proxy": "http://127.0.0.1:12345",

  "http.proxyStrictSSL": false

}

---

📌 为什么要这一步?

* VS Code 默认用系统代理 ([Visual Studio Code][1])

* 但**扩展不一定继承代理**

* 必须手动设置 proxy ([RapidSeedbox][2])

---

# 🧪 验证是否成功

curl -I https://api.openai.com/

👉 正常返回 HTTP 头 = 成功

---

# ❌ 常见错误

| 错误 | 原因 |

| --------------- | ------------------ |

| 用 9090 端口 | 这是控制端口 |

| 写成 LocalForward | 必须是 RemoteForward |

| 只配本地 settings | 必须 Remote Settings |

| 没设环境变量 | 扩展仍无法联网 |

---

# 🎯 总结

只做三件事:

1. SSH 建立代理隧道

2. 远程设置 http_proxy

3. VS Code Remote 设置 proxy

---

# 🔍 SEO关键词

VS Code proxy

Remote SSH proxy

VSCode 无法联网

Codex 登录失败

OpenAI API 代理

Linux 服务器 代理配置

SSH RemoteForward 教程

---

# ⭐ 项目地址

👉 https://github.com/zenggs05/DFT/tree/main/Script

---

# 💬 交流

QQ群:960385428

---

如果这篇对你有帮助,欢迎 Star ⭐

[1]: https://code.visualstudio.com/docs/setup/network?utm\_source=chatgpt.com "Network Connections in Visual Studio Code"

[2]: https://www.rapidseedbox.com/visual-studio-code-proxy?utm\_source=chatgpt.com "VS Code Proxy Configuration - HTTP/HTTPS Setup Guide"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors