WSL 中 GitHub SSH 下载慢的排查与代理配置
最近在 WSL 中遇到一个问题:git fetch GitHub 仓库时速度只有几十 KB/s。最后排查下来,问题并不是 Git 本身,而是 仓库使用 SSH remote,而 SSH 并没有真正经过 Clash 代理。
1. 先确认 Git 使用的是 HTTPS 还是 SSH
执行:
git remote -v
如果输出类似:
origin git@github.com:owner/repo.git (fetch)
origin git@github.com:owner/repo.git (push)
说明当前仓库使用的是 SSH。
这时即使 WSL 中已经配置:
export http_proxy=http://127.0.0.1:7897
export https_proxy=http://127.0.0.1:7897
也不会让 Git SSH 自动走 Clash,因为 http_proxy / https_proxy 主要影响 HTTP(S) 请求,SSH 是另一套连接链路。
2. 让 GitHub SSH 使用 443 端口
编辑:
vim ~/.ssh/config
加入:
Host github.com
HostName ssh.github.com
User git
Port 443
这样可以绕开部分网络环境对 SSH 默认 22 端口的不友好情况。
但这里有一个容易误解的地方:
SSH 改成 443,并不代表 SSH 已经走了 Clash。
如果执行:
ssh -vT git@github.com
日志仍然显示:
Connecting to ssh.github.com [x.x.x.x] port 443.
那本质上依然是 WSL 直接连接 GitHub。
3. 通过 ProxyCommand 让 SSH 真正走 Clash
如果 Clash Verge 的代理端口是 7897,可以利用 nc 把 SSH 流量交给 Clash。
先安装 netcat:
sudo apt install netcat-openbsd
然后把 ~/.ssh/config 改成:
Host github.com
HostName ssh.github.com
User git
Port 443
ProxyCommand nc -X connect -x 127.0.0.1:7897 %h %p
这里:
-X connect:让nc使用 HTTP CONNECT 代理协议-x 127.0.0.1:7897:指定 Clash 的代理地址%h %p:由 SSH 自动替换成目标主机和端口,即ssh.github.com:443
最终链路会变成:
WSL Git
↓
SSH
↓
127.0.0.1:7897
↓
Clash Verge
↓
代理节点
↓
GitHub
4. 如何确认 SSH 真的走了代理
执行:
ssh -vT git@github.com
如果日志中出现:
Executing proxy command: exec nc -X connect -x 127.0.0.1:7897 ssh.github.com 443
并且认证信息里有:
Authenticated to ssh.github.com (via proxy) using "publickey".
就说明 GitHub SSH 已经真正经过 Clash。
正常还会看到:
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
这里最后的 Exit status 1 是正常的,因为 GitHub SSH 只用于 Git 操作,并不提供 shell 登录。
5. 重新测试 Git fetch
执行:
git fetch --progress
这次实际排查中,原本 git fetch 只有大约几十 KB/s;加上 ProxyCommand,让 SSH 真正经过 Clash 后,速度明显提升。
6. 一个容易误判的指标
SSH debug 日志中可能会看到类似:
channel 0: window ... 100000 KiB/s
这个数字不是 Git 实际下载速度,不能拿它判断 git fetch 的真实吞吐。
判断速度应该看:
git fetch --progress
中 Receiving objects 阶段显示的实际速度。
总结
遇到 WSL 中 GitHub 下载慢时,可以优先按下面这个思路判断:
先看 remote 是 HTTPS 还是 SSH
↓
如果是 SSH,http_proxy / https_proxy 不一定有用
↓
GitHub SSH 改走 443
↓
用 ProxyCommand 把 SSH 接入 Clash
↓
ssh -vT 验证是否出现 via proxy
↓
git fetch --progress 看真实速度
这次问题的核心并不是“GitHub SSH 443 太慢”,而是:
之前虽然使用了 443,但仍然是直连 GitHub;真正提速的关键,是让 SSH 流量进入 Clash。