当 github.com 连不上时,怎么把代码推上去
2026/9/14小于 1 分钟
本机 github.com 的 HTTPS 握手直接失败,但 api.github.com 和 ssh.github.com:443 都是通的。这种情况下,SSH over 443 是最省事的解法。
先诊断,别瞎猜
curl -o /dev/null -w "%{http_code}\n" --max-time 12 https://api.github.com
curl -o /dev/null -w "%{http_code}\n" --max-time 12 https://github.com
ssh -T -p 443 git@ssh.github.com三条命令能分清三件事:API 通不通、网页/HTTPS 通不通、SSH 隧道通不通。 我这边的结果是 200 / 000 / Permission denied——说明 443 端口的 SSH 隧道是通的,只是没有授权密钥。
解法:SSH over 443
编辑 ~/.ssh/config:
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile C:/Users/haila/.ssh/id_ed25519
IdentitiesOnly yes然后把公钥加到 GitHub(Settings → SSH and GPG keys → New SSH key)。
验证:
ssh -T git@github.com
# Hi xxx! You've successfully authenticated...之后 remote 用 SSH 地址即可:
git remote set-url origin git@github.com:<user>/<repo>.git一个坑
如果你的 ~/.ssh/config 里已经写了 ProxyCommand 指向某个本地中继脚本,而那个脚本没在跑,SSH 会直接 WinError 10061。 这种情况下直连 ssh -p 443 git@ssh.github.com 反而能通——远程主机名不匹配 Host github.com,就不会走那条坏规则。