快速修复
# ① 分层诊断(30 秒,一锤定音)
curl -s -o /dev/null -w "%{http_code}\n" --max-time 10 https://github.com/ # 200/301 = 网络通,问题在配置/凭据层
GIT_CONFIG_GLOBAL=/dev/null git ls-remote https://github.com/octocat/Hello-World.git # 能列 refs = 配置/凭据层实锤
# ② 网络层(直连不稳):gh-proxy 加速前缀,其余保持匿名 HTTPS
git clone https://gh-proxy.com/https://github.com/<owner>/<repo>.git
# 或走 codeload tarball:curl -sL https://gh-proxy.com/https://codeload.github.com/<owner>/<repo>/tar.gz/refs/tags/<tag> | tar xz
# ③ 配置/凭据层(② 不适用时):删重写规则 + 清失效代理 + gh 重新授权
git config --global --unset-all "url.git@github.com:.insteadof"
git config --global --unset http.proxy && git config --global --unset https.proxy
gh auth logout && gh auth login
做完 ② 或 ③ 后重跑原命令。若 ② 的 gh-proxy 反而更慢/失败,去掉它只保留匿名 HTTPS(镜像有生命周期,用前先 curl -sI 测)。
你会遇到什么
所有依赖 GitHub 的链路在国内直连都不稳:git clone 大仓库卡在 Cloning repository 后被重置;插件/技能 CLI 安装报 443 连不上;marketplace 克隆报 SSH 认证失败;从 Release 下 deb/AppImage 反复断连。
报错五花八门,但根因就三层:网络层(直连不稳)、配置层(git 重写规则/失效代理)、凭据层(SSH key / gh token 状态)。
先分层诊断,再动手,别对着报错瞎试。
本文路径:快速修复(30 秒一段命令)→ 一步步排查(可跳读)→ 原理与变体(症状/原因/证据)。赶时间直接跳到「快速修复」。
为什么会这样
| 层 | 根因 | 典型表现 |
|---|---|---|
| 网络层 | 国内出口到 GitHub 直连不稳定;Release 资产实际托管在 objects.githubusercontent.com,是另一条更差的链路 | Connection reset by peer、443 连不上、下载中断、卡在 Cloning repository |
| 配置层 | 老教程留下的 url.git@github.com:.insteadof=https://github.com/ 把 HTTPS 全重写成 SSH;或失效的 http.proxy 残留 | 公开仓库也报权限错误;任何 clone 都被重置 |
| 凭据层 | SSH key 无效/未配、gh 凭据助手注入失效 token、账号被封 | SSH authentication failed、Permission denied (publickey)、Your account is suspended |
关键认知:公开仓库匿名 HTTPS 即可访问,不需要任何凭据。凡是公开仓库报"权限错误",先怀疑配置层和凭据层,不要怀疑网络。
三层模型对应三条独立链路:网络层是「TCP/TLS 到 github.com 与 objects.githubusercontent.com」的物理可达性,国内出口不稳定时连接在传输层被重置,跟命令无关;配置层是「寻址改写」——insteadOf 把 HTTPS 重写成 SSH、残留 http.proxy 把请求指向失效代理,作用在 git 访问任何远程之前;
凭据层是「认证状态」——SSH key、gh token、账号状态决定公开仓库之外的访问是否被接受。
三层是串联关系:先有可达性(网络),再按配置寻址(配置),最后凭据认证(凭据)——所以排查顺序固定,从下往上:先 curl 直连测网络、再查 insteadOf/proxy、最后验凭据。公开仓库报「权限错误」时,网络层已被排除(能连上才会走到认证),问题只可能在配置层或凭据层。
一步步来
1. 分层诊断 — 必做(30 秒,决定走哪条路)
curl -s -o /dev/null -w "%{http_code}\n" --max-time 10 https://github.com/
- 超时 /
000→ 网络层,走第 2 步; 200/301→ 网络通,继续:
GIT_CONFIG_GLOBAL=/dev/null git ls-remote https://github.com/octocat/Hello-World.git
- 能返回 refs → 配置/凭据层实锤,走第 4 步;
- 同样失败 → 网络层对 git 协议限速/断连,走第 2 步。
2. 网络层:换通道 — 按诊断结果(网络层命中才走)
三种通道按可用性排序(本市场 2026-08-28~30 实测):
# a) gh-proxy 前缀(实测 13.5MB Release 资产秒级)
curl -L -o pkg.deb "https://gh-proxy.com/https://github.com/<owner>/<repo>/releases/download/<tag>/<asset>"
# b) codeload tarball(实测 544K / 2.1s 稳定)
curl -sL https://codeload.github.com/<owner>/<repo>/tar.gz/refs/tags/<tag> | tar xz
# c) 显式代理(有代理时)
git config --global http.https://github.com.proxy http://127.0.0.1:<端口>
tarball 下载断 → 改 git 浅克隆(git clone --depth 1);clone 断 → 改 tarball。两者互换常能绕过坏链路。错峰(避开晚间高峰)与换网络(热点常能绕开)也有效。
SSH over 443(官方通道:SSH 层被墙的出路)
如果 22 端口不通但 SSH key 本身正常,GitHub 官方支持把 SSH 连接走 443 端口(HTTPS 端口,大多数防火墙放行 443 而拦 22)。
# ① 测 443 通道(主机名是 ssh.github.com,不是 github.com)
ssh -T -p 443 git@ssh.github.com
# 成功输出: Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
# ② 单次使用:直接按这个地址 clone
git clone ssh://git@ssh.github.com:443/<owner>/<repo>.git
# ③ 永久生效:写入 ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
User git
首次连接会提示 The authenticity of host '[ssh.github.com]:443 ...' can't be established——这是 known_hosts 里还没有 ssh.github.com 的正常警告;指纹与 GitHub 官方公布的 ED25519 指纹一致即可选 yes。
注意两点:GitHub Enterprise Server 不支持此通道;显式代理可能干扰 443 通道(有代理时优先用 gh-proxy 方案)。
3. 网络层:安装类场景换"不依赖 GitHub"的路径 — 按场景(安装类工具)
- 只想用工具:
pip install <包>(清华镜像-i https://pypi.tuna.tsinghua.edu.cn/simple),不需要 clone 源码; - 技能/插件:tarball 解压后手工复制到对应目录(如
cp -r agent-skills-0.6.7/skills ~/.claude/skills/); - 判断成功看产物(目录/文件就位),不要只看 exit 码(部分 CLI 失败时 exit 码仍为 0)。
4. 配置层:查重写规则与失效代理 — 按诊断结果(配置层命中才走)
git config --global --get-regexp 'url\..*\.insteadof' # 看到 url.git@github.com:.insteadof = 元凶
git config --global --list | grep -i proxy # 代理残留检查
git config --global --unset-all "url.git@github.com:.insteadof"
git config --global --unset http.proxy
git config --global --unset https.proxy
5. 凭据层:SSH 与 gh 凭据助手 — 按诊断结果(凭据层命中才走)
git ls-remote git@github.com:<owner>/<repo> # Permission denied (publickey) = SSH 层问题
git config --global url."https://github.com/".insteadOf "git@github.com:" # 强制 HTTPS(公开仓库匿名即可)
gh auth status # 凭据助手状态
gh auth logout && gh auth login # 重新授权
6. 下载后校验完整性 — 必做(收尾)
du -h pkg.deb # 对照资产页标注大小,差太多 = 断了一半,重下
dpkg-deb -I pkg.deb >/dev/null && echo DEB-OK # 结构可读 = 完整(deb 类)
变体速查表(8 条同根条目并入)
| 变体 | 报错签名 | 场景 | 根因 | 处理 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| clone 被重置/卡死 | fatal: unable to access ... Connection reset by peer / 超时 | 官方 CLI 安装、源码 clone | 直连不稳,大仓库中断 | gh-proxy codeload tarball;pip 替代安装 | ||||||
| 443 连不上 | Failed to connect to github.com port 443 | 插件 /plugin install | 直连 443 被断 | codeload tarball 探路直装;显式代理 | ||||||
| SSH 认证失败 | SSH authentication failed / Permission denied (publickey) | marketplace / 插件克隆 | CLI 默认走 SSH,本机无有效 key | 强制 HTTPS insteadOf + 可选 gh-proxy 加速 | ||||||
| 公开仓库报权限错误 | Your account is suspended / Please make sure you have the correct access rights and the repository exists | 网络通但 clone 一律失败 | HTTPS→SSH 全局重写 + 账号/凭据异常 | 匿名 HTTPS 验证 + --unset-all 重写规则;gh auth 重新登录 | ||||||
| Release 资产下载断连 | TLS 断连 / 下载中断 | deb/AppImage 资产下载 | 资产走 objects.githubusercontent.com 不稳 | gh-proxy 前缀 + 下载后校验大小 | ||||||
| zip/tarball 下载超时中断 | 下载超时/中断 | 技能/插件 zip 下载 | codeload/raw 链路不稳 | 换通道(tarball ↔ clone 互转);镜像站离线解压 | ||||||
| 失效本地代理残留 | clone 被重置(配置了死代理) | 任何 clone | http.proxy 残留指向已挂代理 | --unset 清代理 | ||||||
| 代理可用但写操作失败(外部 Issue #6689) | unable to push data to server behind socks5 proxy | 有代理但 gh push/上传失败 | socks5 代理与 gh 写链路不兼容 | 换 http 代理或对 gh 直连;以 push 成功为准(未本地复现) | 失效本地代理残留 | clone 被重置(配置了死代理) | 任何 clone | http.proxy 残留指向已挂代理 | --unset 清代理 | |
| 工具运行时依赖 GitHub | 构建/更新时访问 GitHub 卡住 | 工具依赖 GitHub 的场景 | 工具少量 GitHub 依赖 | 核心流程离线跑;pip 走清华镜像;gh-proxy |
怎么确认修好了
- 网络层:原命令(clone / 下载 / 安装)完整跑完,无
reset by peer/Timed out;下载类对照资产页大小一致。 - 配置层:
GIT_CONFIG_GLOBAL=/dev/null git ls-remote https://github.com/octocat/Hello-World.git返回 refs;重写规则与失效代理已删。 - 凭据层:公开仓库匿名 HTTPS 可 clone;需要 SSH 的场景
git ls-remote git@github.com:...不再报Permission denied;22 端口被拦时ssh -T -p 443 git@ssh.github.com能认证成功。- 凭据层:公开仓库匿名 HTTPS 可 clone;需要 SSH 的场景git ls-remote git@github.com:...不再报Permission denied。 - 安装类:看产物就位(目录/文件),不看 exit 码。
其它环境的表现
| 环境 | 说明 |
|---|---|
| 国内直连 | clone/下载不稳是常态;gh-proxy / codeload / 错峰 / 换网络 |
| 校园网/家宽 | 晚间高峰最差,错峰或代理 |
| 有稳定代理 | 直连即可,gh-proxy 仅备选;记得清掉失效代理残留 |
| Windows/macOS | 同样分层;tarball 方式相同,路径对应各平台用户目录 |
| 完全离线 | clone/下载不可用;本地工具核心流程仍可跑 |
症状
git clone卡在 Cloning repository 后报Connection reset by peer/ 超时;Failed to connect to github.com port 443;SSH authentication failed/Permission denied (publickey);- 公开仓库也报
Please make sure you have the correct access rights and the repository exists; - Release / zip / tarball 下载反复断连、TLS 中断;
- 部分 CLI 失败时 exit 码仍为 0(坑)。
原因
国内出口到 GitHub 直连不稳定(Release 资产另走 objects.githubusercontent.com,链路更差);老教程留下的 HTTPS→SSH 全局重写规则与失效代理残留放大问题;SSH key / gh 凭据 / 账号状态异常时,连公开仓库也被拒。
解法
- 分层诊断:
curl https://github.com/+GIT_CONFIG_GLOBAL=/dev/null git ls-remote区分网络层/配置层/凭据层; - 网络层换通道:gh-proxy 前缀、codeload tarball、浅克隆、显式代理、错峰/换网络;SSH 被墙时走官方 443 通道(ssh.github.com);2. 网络层换通道:gh-proxy 前缀、codeload tarball、浅克隆、显式代理、错峰/换网络;
- 安装类换不依赖 GitHub 的路径:pip 清华镜像、tarball 手工复制;判断成功看产物不看 exit 码;
- 配置层删重写规则与失效代理;凭据层强制 HTTPS / gh 重新授权;
- 下载后校验大小/结构。
验证证据
- 2026-08-29 实测:
GIT_CONFIG_GLOBAL=/dev/null git ls-remote https://github.com/octocat/Hello-World.git匿名返回全部 refs;--unset-all url.git@github.com:.insteadof后公开仓库 clone 成功。 - 2026-08-28 实测:CLI clone 被重置(Recv failure: Connection reset by peer),gh-proxy codeload tarball 277KB 秒级完成,24 技能目录就位。
- 2026-08-28 实测:SSH 认证失败 → 强制 HTTPS
insteadOf后SSH not configured, cloning via HTTPS+ marketplace 添加成功。 - 2026-08-28 实测:codeload tarball 544K / 2.1s 稳定;gh-proxy 7.8s 可用;raw 端点探针超时统一避开。
- 2026-08-28 实测:gh-proxy 下载 13.5MB 秒级,deb 结构确认 exit=0;直连 assets 断连。
- 收录走 PyPI 清华镜像成功;GitHub 直连风险在连通性记录标注。
- 未实测:各镜像加速站的生命周期(有挂/变慢风险,用前先测);完整企业网络环境(代理白名单等)。
相关 canonical
按「同根(网络层出口不稳,换源家族)」读:
- pip 安装超时/慢(网络层同类,PyPI 源配置)
- npm install 慢/挂起(网络层同类,npm 源配置)
- Go 模块拉取慢/超时(网络层同类,Go proxy 配置)
- docker pull 失败/镜像加速(网络层同类)
- 只有个别网站打不开(其他网站正常)——分层定位(同分层思路:先 curl 定位网络层)
报错相近但根因不同:TLS/证书类问题。
参考资料
- GitHub Docs: Using SSH over the HTTPS port — <https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port>
适用工具 (1)
本问题方案已挂到下列工具的方案页——从工具页也能回到这里,双向可达。
git · 外部工具成套方案 (组合包)
这个问题包含在下列成套安装方案中。
- 国内网络一键配源 partial
来源与证据
← 编码代理与终端 问题域 | 问题货架 | 遇到其它问题?去 问题空间 提交求助卡