# 错误：命令以退出状态 128 失败：git clone --filter=blob:none 'git@github.com:user/private-repo.git' /tmp/pip-install-xxx/package。请检查日志以获取完整命令输出。stderr：git@github.com：权限被拒绝（公钥）。致命错误：无法从远程仓库读取。请确保您拥有正确的访问权限并且仓库存在。

- **ID:** `pip/vcs-git-clone-permission-denied-public-key`
- **领域:** pip
- **类别:** auth_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Pip 尝试通过 SSH 克隆私有 Git 仓库，但 SSH 密钥未配置或未被远程服务器接受，导致公钥认证失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.0 | active | — | — |
| pip 23.2 | active | — | — |
| pip 24.0 | active | — | — |
| git 2.40 | active | — | — |

## 解决方案

1. ```
   生成 SSH 密钥对并将公钥添加到您的 GitHub 帐户：ssh-keygen -t ed25519 -C 'your_email@example.com'；cat ~/.ssh/id_ed25519.pub（复制输出）；转到 GitHub 设置 > SSH 和 GPG 密钥 > 新建 SSH 密钥；粘贴并保存。然后重试 pip install。
   ```
2. ```
   在 requirements 文件中使用 HTTPS 而不是 SSH 作为 Git URL：将 git+ssh://git@github.com/user/private-repo.git 替换为 git+https://github.com/user/private-repo.git，并使用个人访问令牌（PAT）进行身份验证：pip install git+https://<PAT>@github.com/user/private-repo.git
   ```
3. ```
   如果仓库是公开的，将 URL 更改为使用无需身份验证的公共 HTTPS 克隆 URL：git+https://github.com/user/public-repo.git
   ```

## 无效尝试

- **Using pip install with --no-deps to skip VCS dependencies** — This only avoids the error for the current install but leaves the missing dependency unresolved, causing import errors later. (95% 失败率)
- **Adding the SSH key to the ssh-agent with ssh-add without checking the key is correct for the repository** — If the key is not added to the GitHub account or is the wrong key type, authentication still fails. (60% 失败率)
- **Setting GIT_SSH_COMMAND='ssh -v' to debug but not fixing the underlying key issue** — Debugging alone does not resolve the authentication failure. (90% 失败率)
