为 GitHub 设置代理
作者: ryan 发布于: 8/28/2023 更新于: 8/28/2025 字数: 0 字 阅读: 0 分钟
ssh -T git@github.com
之前一直报
bash
CreateProcessW failed error:2
posix_spawnp: No such file or directory
问题原因
connect
命令未找到(用于代理的 Helper 程序)- Git 的
usr/bin
目录未添加到系统 PATH - 可能未安装完整版的 Git for Windows
1. 将 Git 的 bin 目录添加到系统 PATH
- 找到 Git 的安装路径(默认
C:\Program Files\Git
) - 在 PowerShell 中运行:
bash
$env:Path += ";C:\Program Files\Git\usr\bin"
永久添加到 PATH(推荐):
- 系统属性 → 高级 → 环境变量
- 编辑 "Path" → 添加
C:\Program Files\Git\usr\bin
2. 确认 connect 工具存在
检查是否安装了 connect.exe
bash
Get-ChildItem "C:\Program Files\Git\usr\bin\connect.exe"
如果缺失,重新安装完整版 Git for Windows:https://git-scm.com/download/win
3. 修改 SSH 配置
修改 ~/.ssh/config
文件
bash
Host github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "C:\Users\用户名\.ssh\id_rsa"
TCPKeepAlive yes
ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p
Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "C:\Users\用户名\.ssh\id_rsa"
TCPKeepAlive yes
ProxyCommand "C:\Users\用户名\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 -a none %h %p
使用 ssh 命令测试没问题
成功连接应显示:
bash
$ ssh -T github.com
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@github.com
Hi <name>! You've successfully authenticated, but GitHub does not provide shell access.