欢迎光临
我们一直在努力

Codex App SSH 远程开发教程:本地连接远程服务器项目

推荐试用以下开源项目更快速便捷地做 Codex App SSH 多服务器群远程开发:https://jurio.blog.csdn.net/article/details/162584556 项目地址:https://github.com/Jurio0304/CodexHub Release 下载:https://github.com/Jurio0304/CodexHub/releases

如果你的代码、数据、Conda 环境或 GPU 都在远程 Linux 服务器上,而你希望在本地 Windows / macOS 上使用 Codex App 直接开发远程项目,可以使用 Codex App 的 SSH 远程连接功能。

简单来说,它的作用是:

本地 Codex App
↓
读取本机 SSH 配置
↓
连接远程服务器
↓
在远程项目目录中读写代码、运行命令

也就是说,Codex App 的界面运行在本地,但实际项目文件、命令执行和环境调用都发生在远程服务器上。


一、适用场景

Codex App SSH 远程开发适合以下情况:

  • 本地电脑性能有限,远程服务器有 GPU;
  • 项目代码和数据都在服务器上;
  • 希望 Codex 直接修改远程代码、运行测试、排查环境问题;
  • 远程服务器已经配置好 Conda、CUDA、PyTorch、数据库等环境;
  • 希望通过一个本地 Codex App 管理多个远程项目。

  • 二、准备条件

    开始前需要准备:

    项目说明
    本地电脑 Windows 或 macOS,已安装 Codex App
    远程服务器 Linux 服务器,可通过 SSH 登录
    SSH 密钥 推荐使用 ed25519 密钥
    SSH config 本机 ~/.ssh/config 中配置具体 Host
    远程 Codex CLI 远程服务器上可以运行 codex 命令
    Codex 认证 远程服务器上的 Codex 已登录

    三、本地配置 SSH

    1. 检查 OpenSSH

    Windows PowerShell 或 macOS 终端中执行:

    ssh -V

    如果能看到 OpenSSH 版本信息,说明已经安装。


    2. 生成 SSH 密钥

    Windows PowerShell:

    mkdir $HOME\\.ssh –Force
    ssh-keygen –t ed25519 –C "codex-app"

    macOS / Linux:

    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
    ssh-keygen -t ed25519 -C "codex-app"

    默认会生成:

    ~/.ssh/id_ed25519
    ~/.ssh/id_ed25519.pub

    其中 id_ed25519 是私钥,不要泄露;id_ed25519.pub 是公钥,可以添加到远程服务器。


    四、把公钥添加到远程服务器

    假设服务器信息如下:

    远程用户:your_user
    服务器地址:your.server.com
    SSH 端口:22

    Windows PowerShell:

    type $HOME\\.ssh\\id_ed25519.pub | ssh your_user@your.server.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

    macOS / Linux:

    cat ~/.ssh/id_ed25519.pub | ssh your_user@your.server.com 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

    第一次连接时,如果出现:

    Are you sure you want to continue connecting (yes/no/[fingerprint])?

    确认服务器无误后输入:

    yes


    五、配置本机 SSH config

    Codex App 会读取本机 ~/.ssh/config 中的 Host 别名,因此需要先配置 SSH Host。

    Windows 路径

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

    可用 PowerShell 打开:

    notepad $HOME\\.ssh\\config

    macOS / Linux 路径

    ~/.ssh/config

    可用终端编辑:

    nano ~/.ssh/config

    写入如下内容:

    Host remote-dev
    HostName your.server.com
    User your_user
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

    字段说明:

    字段说明
    Host 本地 SSH 别名,也是 Codex App 识别的名称
    HostName 服务器 IP 或域名
    User 远程用户名
    Port SSH 端口
    IdentityFile 本地私钥路径
    IdentitiesOnly 只使用指定私钥

    Windows 下注意文件名必须是 config,不要保存成 config.txt。


    六、测试 SSH 连接

    在本地终端执行:

    ssh remote-dev

    如果能成功进入远程服务器,说明 SSH 配置基本正确。

    继续测试非交互命令:

    ssh remote-dev 'pwd && whoami && hostname'

    Windows PowerShell:

    ssh remote-dev "pwd && whoami && hostname"

    如果这一步失败,Codex App 中也无法正常连接该远程服务器。


    七、在远程服务器安装 Codex CLI

    登录远程服务器:

    ssh remote-dev

    安装 Codex CLI:

    curl -fsSL https://chatgpt.com/codex/install.sh | sh

    安装后检查:

    which codex
    codex –version

    如果能看到 codex 的路径和版本号,说明安装成功。


    八、远程服务器登录 Codex

    在远程服务器执行:

    codex login

    如果远程服务器没有浏览器,可以尝试:

    codex login –device-auth

    如果仍然不方便登录,也可以在安全前提下复制本地认证文件到远程服务器:

    ssh remote-dev 'mkdir -p ~/.codex'
    scp ~/.codex/auth.json remote-dev:~/.codex/auth.json

    注意:auth.json 包含访问凭证,应当像密码一样保护,不要提交到 Git,也不要发给他人。


    九、确保远程 shell 能找到 codex

    这一步非常关键。不要只在远程终端中手动运行 codex –version,还要从本地测试:

    ssh remote-dev 'command -v codex && codex –version'

    如果输出了 codex 路径和版本,说明 Codex App 通过 SSH 启动远程服务时也大概率可以找到它。

    如果报错:

    codex: command not found

    说明远程 shell 的 PATH 没有包含 Codex 所在目录。可以在远程服务器执行:

    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

    然后重新测试:

    ssh remote-dev 'command -v codex && codex –version'


    十、在 Codex App 中添加 SSH 连接

    完成前面的配置后,打开本地 Codex App,进入:

    Settings
    → Connections
    → SSH / Remote connections
    → Add or enable SSH host
    → 选择 remote-dev
    → 选择远程项目目录

    远程项目目录可以是:

    /home/your_user/project_name
    /home/your_user/workspace/project_name

    进入项目后,建议先发送一个安全测试:

    请先不要修改任何文件。请依次执行 pwd、hostname、whoami、git status 和 ls -la,然后总结当前项目目录、Git 状态和运行环境。

    如果返回的是远程服务器路径,说明 Codex App 已经成功进入远程项目。


    十一、常见问题排查

    1. Codex App 看不到 SSH Host

    检查:

    cat ~/.ssh/config
    ssh remote-dev

    Windows PowerShell:

    Test-Path $HOME\\.ssh\\config
    Get-Content $HOME\\.ssh\\config
    ssh remote-dev

    常见原因:

    • config 文件不存在;
    • Windows 下误保存成了 config.txt;
    • Host 没有写成具体别名;
    • 修改 SSH config 后没有重启 Codex App。

    推荐写法:

    Host remote-dev
    HostName your.server.com
    User your_user


    2. SSH 提示 Permission denied

    常见原因:

    • 公钥没有添加到远程服务器;
    • IdentityFile 指向了错误私钥;
    • 远程用户名写错;
    • .ssh 权限不正确。

    远程服务器权限建议:

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

    macOS / Linux 本地私钥权限建议:

    chmod 600 ~/.ssh/id_ed25519


    3. Codex App 报 codex command not found

    本地执行:

    ssh remote-dev 'command -v codex && codex –version'

    如果失败,远程服务器上补充 PATH:

    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile
    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc


    4. Conda 环境不可用

    如果 Codex 运行命令时报:

    conda: command not found

    可以在远程服务器执行:

    conda init bash

    也可以在任务中明确告诉 Codex:

    运行项目前,请先执行:
    source ~/miniconda3/etc/profile.d/conda.sh
    conda activate your_env_name
    然后再运行测试命令。


    十二、安全建议

    Codex App SSH 远程开发会让 Codex 在远程服务器上读写文件和执行命令,因此建议:

  • 不要使用 root 用户运行 Codex;
  • 不要把 ~/.codex/auth.json 提交到 Git;
  • 不要把 Codex 相关服务端口直接暴露到公网;
  • 优先通过 SSH、VPN、内网或 Tailscale 等方式访问远程服务器;
  • 让 Codex 修改代码前,先确认当前 Git 状态。
  • 推荐每次开始前先执行:

    git status

    必要时提前创建新分支:

    git checkout -b codex/remote-task


    十三、最终检查清单

    在 Codex App 中连接远程项目之前,建议依次检查:

    ssh remote-dev
    ssh remote-dev 'pwd && whoami && hostname'
    ssh remote-dev 'command -v codex && codex –version'
    ssh remote-dev 'ls -la /home/your_user/project_name'
    ssh remote-dev 'cd /home/your_user/project_name && git status'

    如果以上命令都正常,再打开 Codex App:

    Settings
    → Connections
    → SSH
    → remote-dev
    → 选择远程项目目录


    总结

    Codex App SSH 远程开发的关键链路是:

    本机 SSH config 配置正确
    ↓
    本地 ssh remote-dev 可以连接服务器
    ↓
    远程服务器已安装并登录 Codex
    ↓
    本地可以通过 SSH 找到远程 codex 命令
    ↓
    Codex App 识别 SSH Host
    ↓
    选择远程项目目录开始开发

    其中最重要的测试命令是:

    ssh remote-dev 'command -v codex && codex –version'

    只要这一步能成功,Codex App 的 SSH 远程开发通常就已经完成了大部分准备工作。


    推荐试用以下开源项目更快速便捷地做 Codex App SSH 多服务器群远程开发:https://jurio.blog.csdn.net/article/details/162584556 项目地址:https://github.com/Jurio0304/CodexHub Release 下载:https://github.com/Jurio0304/CodexHub/releases


    赞(0)
    未经允许不得转载:171主机测评 » Codex App SSH 远程开发教程:本地连接远程服务器项目
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址