Cursor 连接远程 Docker / Dev Container 失败问题总结
1. 问题现象这次问题不是单纯的 SSH 连不上而是 Cursor 在多层远程链路中某一层失败Windows Cursor - Remote SSH 连接远端宿主机 192.168.206.112 / 192.168.206.140 - Cursor Server 在远端宿主机启动 - Dev Containers 尝试 attach 到 Docker 容器 magatron / f3673e625a77 - 容器内 Cursor Server / extension host / WebSocket 连接失败常见报错包括Failed to connect to the remote extension host server Error: WebSocket close with status code 1006Could not fetch remote environmentSocket-mode code server reported /tmp/cursor-remote-ssh-; expected /tmp/cursor-remote-ssh-xxxx/code.sockNo remote exec server found for authority: dev-container...ssh-remote...; using localFailed to read .gitconfig: TypeError [ERR_INVALID_ARG_TYPE]: The path argument must be of type string. Received undefinedEADDRINUSE: address already in use 127.0.0.1:372652. 关键判断2.1 SSH 层通常是成功的日志里多次出现SSH connection established以及Server install command exit code: 0这说明 SSH 本身不是主要问题。2.2 远端宿主机 Cursor Server 也能启动日志里出现过exitCode0 isFatalErrorfalse codeListeningOn/tmp/cursor-remote-ssh-.../code.sock说明远端宿主机上的 Cursor Server 能启动。2.3 Docker 本身也基本正常日志里出现docker info: Command completed with exit code 0 docker inspect f3673e625a77: Command completed with exit code 0说明 Docker 服务正常容器也能被 inspect 到。2.4 真正失败点在 Cursor Remote-Containers / Dev Containers 上下文最关键的报错是No remote exec server found for authority: dev-container...ssh-remote...; using local随后出现Failed to read .gitconfig: TypeError [ERR_INVALID_ARG_TYPE]: The path argument must be of type string. Received undefined这说明 Cursor 本来应该通过远端 SSH 上下文去 attach Docker 容器但过程中 remote exec server 上下文丢失导致 Cursor 退回到本地上下文最终路径解析出错。3. 主要原因汇总原因 1Cursor Remote-SSH 输出被 Windows 终端控制字符污染日志中出现大量类似内容Microsoft Windows [版本 ...] C:\Users\...\cmd.EXE \x1b[10;40H同时 socket 路径被截断Socket-mode code server reported /tmp/cursor-remote-ssh-; expected /tmp/cursor-remote-ssh-xxxx/code.sock说明 Cursor 在解析远端返回的 socket 路径时被终端控制字符、换行或 cmd 输出污染。解决方向关闭 socket mode关闭登录终端显示使用干净的 SSH config避免.bashrc输出欢迎信息、echo、clear、conda activate等内容原因 2Cursor / DevContainer 残留进程和 socket 文件冲突日志中多次出现Multiplex server script is already running Code server script is already running Server script is already running这说明旧的 Cursor Server、multiplex server、forwarder、devcontainer-cli 进程仍在运行。它们可能持有旧 token、旧 socket 或旧端口导致新连接失败。解决方向杀掉旧 Cursor 相关进程删除远端/tmp/cursor-remote-ssh-*删除远端/tmp/devcontainer-cli-*删除容器内/root/.cursor-server原因 3Dev Container 端口转发冲突日志里出现EADDRINUSE: address already in use 127.0.0.1:37265这说明某个本地或远端转发端口已经被占用。Cursor 会不断尝试新的 forwarder但如果状态混乱最终会导致 extension host 连接失败。解决方向关闭本地 Cursor杀掉本地 ssh.exe清理远端 forwarder.js / devcontainer-cli避免从旧的 Recent Project 直接恢复连接原因 4Cursor Dev Containers 缓存损坏或上下文丢失关键报错No remote exec server found for authority: dev-container...ssh-remote...; using local以及The path argument must be of type string. Received undefined这说明 Cursor 的 Remote Containers 状态损坏或者从旧的 Recent Container 入口进入时没有正确拿到 SSH 上下文。解决方向清理本地 Cursor 的anysphere.remote-containers缓存不要直接点旧的 Recent Project先 Remote SSH 到宿主机再 Attach Running Container原因 5.gitconfig/ GPG / known_hosts 缺失引发干扰日志里有Failed to read /home/pcljgy/.ssh/known_hostsgpg: Fatal: cant open /home/pcljgy/.gnupg/trustdb.gpg这些一般不是根因但会增加连接过程中的异常分支。后面真正致命的是.gitconfigpath 为 undefined。解决方向在远端宿主机创建空的 known_hosts初始化.gnupg关闭 Dev Containers 自动复制 Git 配置原因 6在 Docker 内执行pkill -u $USER时$USER为空Docker 内报过pkill使用帮助原因通常是执行了pkill-u$USER-fcursor-server但容器内$USER为空实际变成pkill-u-fcursor-server所以pkill报 usage。解决方式容器内不要用-u $USER改用pkill-fcursor-server||true宿主机上可以用pkill-u$(id-u)-fcursor-server||true4. 推荐的一次性修复流程4.1 Windows 本地关闭 Cursor 和 SSH在 Windows PowerShell 执行taskkill/F/IM Cursor.exe taskkill/F/IM ssh.exe如果ssh.exe中有其他重要连接不要直接杀所有 ssh.exe可以用更精确的方式Get-CimInstanceWin32_Process|Where-Object{$_.Name-eqssh.exe-and$_.CommandLine-like*cursor-remote-ssh*}|ForEach-Object{Stop-Process-Id$_.ProcessId-Force}4.2 清理本地 Cursor Remote Containers 缓存PowerShell 执行Rename-Item$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-containers$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-containers.bak-ErrorAction SilentlyContinue如果仍失败再清理 Remote SSH 缓存Rename-Item$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-ssh$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-ssh.bak-ErrorAction SilentlyContinue4.3 配置 Windows SSH config打开notepad$env:USERPROFILE\.ssh\config加入Host pcl112 HostName 192.168.206.112 User pcljgy RequestTTY no ServerAliveInterval 30 ServerAliveCountMax 3 TCPKeepAlive yes LogLevel ERROR测试ssh-T pcl112echo ok理想输出只应该是ok如果出现欢迎语、乱码、conda 信息、颜色控制符就说明远端 shell 启动脚本仍然污染输出。4.4 远端宿主机补齐基础文件登录远端宿主机ssh pcljgy192.168.206.112在宿主机执行mkdir-p~/.ssh ~/.gnupgtouch~/.ssh/known_hostschmod700~/.ssh ~/.gnupgchmod600~/.ssh/known_hosts gpg --list-keys/dev/null21||true4.5 清理远端宿主机 Cursor 残留在 206.112 宿主机执行pkill-u$(id-u)-fcursor-server||truepkill-u$(id-u)-fmultiplex-server||truepkill-u$(id-u)-fcursor-remote||truepkill-u$(id-u)-fdevcontainer-cli||truepkill-u$(id-u)-fforwarder.js||truerm-rf~/.cursor-serverrm-rf/tmp/cursor-remote-ssh-*rm-rf/tmp/devcontainer-cli-*rm-rf/run/user/$(id-u)/cursor-remote-*2/dev/null||true4.6 清理 Docker 容器内 Cursor 残留如果容器 ID 是f3673e625a77在宿主机执行dockerexec-uroot f3673e625a77sh-lc pkill -f cursor-server || true pkill -f multiplex-server || true pkill -f cursor-remote || true pkill -f devcontainer-cli || true pkill -f forwarder.js || true rm -rf /root/.cursor-server rm -rf /tmp/cursor-remote-ssh-* rm -rf /tmp/devcontainer-cli-* rm -rf /run/user/*/cursor-remote-* 2/dev/null || true 如果容器里没有重要运行任务可以重启容器dockerrestart f3673e625a774.7 修改 Cursor 设置打开notepad$env:APPDATA\Cursor\User\settings.json加入或合并以下配置{remote.SSH.showLoginTerminal:false,remote.SSH.useLocalServer:false,remote.SSH.remoteServerListenOnSocket:false,dev.containers.copyGitConfig:false,remote.containers.copyGitConfig:false}重点配置说明remote.SSH.remoteServerListenOnSocket:false用于避免 socket mode 下 socket 路径解析和任意 TCP 转发问题。dev.containers.copyGitConfig:false,remote.containers.copyGitConfig:false用于绕开.gitconfigpath undefined 相关问题。4.8 正确重新连接流程不要直接点 Cursor 首页的旧 Recent Project例如Container magatron (f3673e625a77)应该按这个顺序1. 打开 Cursor 2. Remote-SSH: Connect to Host... 3. 选择 pcl112 或 192.168.206.112 4. 等左下角显示已经 SSH 连接到远端宿主机 5. 再执行 Dev Containers: Attach to Running Container... 6. 选择 magatron / f3673e625a77 7. 再打开 /workspace 或 /root/workspace5. 排查命令5.1 判断 Docker 容器本身是否可进入在远端宿主机执行dockerps-a|grepf3673e625a77dockerinspect-f{{.State.Status}} {{.State.Running}} {{.State.ExitCode}} {{.Name}}f3673e625a77dockerexec-itf3673e625a77bash如果bash不存在dockerexec-itf3673e625a77sh如果手动docker exec都进不去问题在 Docker / 容器本身不是 Cursor。如果手动docker exec能进去但 Cursor 进不去问题在 Cursor Remote Containers / 端口转发 / 缓存状态。5.2 查看容器内 Cursor Server 日志dockerexec-uroot f3673e625a77sh-lc ls -lh /root/.cursor-server/ tail -200 /root/.cursor-server/*.log 2/dev/null || true 5.3 检查远端宿主机资源df-hdf-ihfree-hls-ld/tmp /run/user/$(id-u)~如果磁盘满了、inode 满了、/tmp不可写Cursor Server 也可能启动失败。5.4 检查是否被 OOM 杀掉dmesg-T|tail-100|grep-iEkilled|oom|cursor|node6. 最短可执行修复版Windows PowerShelltaskkill/F/IM Cursor.exe taskkill/F/IM ssh.exeRename-Item$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-containers$env:APPDATA\Cursor\User\globalStorage\anysphere.remote-containers.bak-ErrorAction SilentlyContinue远端宿主机mkdir-p~/.ssh ~/.gnupgtouch~/.ssh/known_hostschmod700~/.ssh ~/.gnupgchmod600~/.ssh/known_hostspkill-u$(id-u)-fcursor-server||truepkill-u$(id-u)-fmultiplex-server||truepkill-u$(id-u)-fcursor-remote||truepkill-u$(id-u)-fdevcontainer-cli||truepkill-u$(id-u)-fforwarder.js||truerm-rf~/.cursor-serverrm-rf/tmp/cursor-remote-ssh-*rm-rf/tmp/devcontainer-cli-*rm-rf/run/user/$(id-u)/cursor-remote-*2/dev/null||true容器内清理dockerexec-uroot f3673e625a77sh-lc pkill -f cursor-server || true pkill -f multiplex-server || true pkill -f cursor-remote || true pkill -f devcontainer-cli || true pkill -f forwarder.js || true rm -rf /root/.cursor-server rm -rf /tmp/cursor-remote-ssh-* rm -rf /tmp/devcontainer-cli-* Cursor settings.json{remote.SSH.showLoginTerminal:false,remote.SSH.useLocalServer:false,remote.SSH.remoteServerListenOnSocket:false,dev.containers.copyGitConfig:false,remote.containers.copyGitConfig:false}7. 最终结论这次 Cursor 连接失败的核心不是 Docker 不可用也不是 SSH 密码或网络问题。更准确的结论是Cursor Remote-SSH 能连上宿主机 Docker 容器也能被 inspect 容器内 Cursor Server 也能安装并监听端口 但 Cursor Remote-Containers 的远程上下文丢失或缓存状态损坏 导致 attach 容器时退回本地上下文最终 .gitconfig 路径变成 undefined 并伴随 socket mode、端口转发和旧进程残留问题。推荐的解决策略是清理本地 Cursor remote-containers 缓存 清理远端宿主机和容器内 Cursor 残留 关闭 socket mode 和 Git config 自动复制 不要从旧 Recent Project 直接恢复连接 先 Remote-SSH 到宿主机再 Attach Running Container