Problem entry · machine-readable · 编码代理与终端

git clone 公开仓库报 fatal: Could not read from remote repository / Please make sure you have the correct access rights and the repository exists(网络正常)

本页嵌入 #trove-entity JSON(本条目全量结构化数据);全库数据见 /agent/trove.json。

元数据

idgithub-clone-fail收录2026-08-29
问题域编码代理与终端主题分组网络与镜像
适用工具git · 外部工具

症状

clone 一个**公开仓库**(浏览器能打开、curl 也通),git 却报:

```

ERROR: Your account is suspended. Please visit https://support.github.com for more information.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

```

特征:

- 网络是通的:网页能打开、`curl https://github.com/` 返回 200,但 git 一律失败(exit 128);

- 报错指向「权限」而不是「网络」;`fatal: unable to access ... Timed out` 类报错属网络层,不在本篇;

- 之前能 clone、某天突然全挂,或换机器/换账号后开始出现;

- 文案极具迷惑性:GitHub 对失效账号返回的 403/404 是同一句 "Please make sure you have the correct access rights and the repository exists",连公开仓库也一样,容易误判为网络/仓库问题。

原因

最常见:**全局 git 配置把 HTTPS 重写成了 SSH**(老教程教「强制走 SSH」留下的配置):

```

url.git@github.com:.insteadof=https://github.com/

```

重写后所有 `https://github.com/...` 的 clone 实际走 `git@github.com:...`(SSH)。SSH 认证用的是本机 SSH key / gh 凭据助手绑定的账号——一旦该账号状态异常(被封禁/风控、key 被删、token 失效),连**匿名即可访问的公开仓库**也被拒绝。

次要来源:`credential.https://github.com.helper=!/usr/bin/gh auth git-credential`(gh CLI 凭据助手)向 HTTPS 注入失效/被封的 token,同样报 access rights。

解法

1. **先分层**:`curl -s -o /dev/null -w "%{http_code}" --max-time 10 https://github.com/` 返回 200/301 → 网络通,问题在 git 配置/凭据层;超时或 000 → 网络层(见第 6 条)。

2. **查重写规则**:`git config --global --get-regexp 'url\..*\.insteadof'`。看到 `url.git@github.com:.insteadof https://github.com/` 就是元凶。

3. **匿名 HTTPS 验证**(不改任何配置,一锤定音):

`GIT_CONFIG_GLOBAL=/dev/null git ls-remote https://github.com/octocat/Hello-World.git`

能返回 refs → 配置问题实锤;同样失败 → 才是网络/远端问题。

4. **修复**:删除重写规则(公开仓库走匿名 HTTPS 即可):

`git config --global --unset-all "url.git@github.com:.insteadof"`

然后重新 clone 验证。若确实需要 SSH 通道(私有仓库/写权限),去处理账号本身:换有效 SSH key 或 `gh auth login` 重新授权——不要保留重写规则让所有 HTTPS 都踩坑。

5. **凭据助手脏凭据**:`git config --global --list | grep credential` 看有没有 `!/usr/bin/gh auth git-credential`;`gh auth status` 检查账号状态,失效则 `gh auth logout` 后 `gh auth login`(公开仓库其实不需要任何凭据)。

6. **若第 1 步确认是网络层**(国内直连超时/重置):配代理 `git config --global http.https://github.com.proxy http://127.0.0.1:<端口>`(按代理端口,`http://`/`socks5://` 均可);或临时走加速前缀 `git clone https://gh-proxy.com/https://github.com/<owner>/<repo>.git`——2026-08-29 校园网实测 gh-proxy.com / ghfast.top / ghproxy.homeboyc.cn 存活(加速站有生命周期,用前先 curl 测)。

验证证据

- 本地实测(2026-08-29,校园网无代理,git 2.53.0,公开仓库 octocat/Hello-World):

- 网络层:curl github.com → 200;

- 匿名 HTTPS(`GIT_CONFIG_GLOBAL=/dev/null`):ls-remote 返回全部 refs(成功);

- 默认配置:同命令 exit 128,报 `ERROR: Your account is suspended` + `Please make sure you have the correct access rights and the repository exists`;

- 显式 SSH(`git@github.com:...`):同样 exit 128 → 证明 HTTPS 被全局重写规则转到了 SSH,而 SSH 绑定的账号已被 GitHub 封禁;

- 修复验证:备份全局配置 → `git config --global --unset-all url.git@github.com:.insteadof` → `git clone --depth 1` 成功(exit 0,产物完整)→ 恢复原配置。

- 实测复现日志(2026-08-29)

来源与证据

素材来源:https://www.cnblogs.com/security-hyacinth/p/19771648

验证证据:Evidence details kept locally (2026-08-29)