Skip to content

Permission 拒绝 (Publickey)

错误信息

                [email protected]: Permission 拒绝 (publickey).
              

快速摘要

你的 SSH 键是不配置正确地 or 是不 associated 使用你的 GitHub account, 所以 remote 拒绝你的连接.

为什么发生

  • 否 SSH 键是 generated or 添加到你的 SSH agent

  • SSH 键是不添加到你的 GitHub account

  • SSH agent 是不运行 or 做不有你的键加载

  • 错误 remote URL 格式 (using SSH 当你应该 use HTTPS)

最小示例

✗ 错误代码
git push origin main  # [email protected]: Permission denied (publickey).
✓ 修复代码
# Generate and add SSH key
ssh-keygen -t ed25519 -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy ~/.ssh/id_ed25519.pub to GitHub Settings > SSH
git push origin main  # now succeeds

Generate SSH 键, 添加它到 SSH agent and 你的 GitHub account, 然后推送将工作.

如何诊断

  • 测试 SSH 连接: ssh -T [email protected]

  • 检查 for SSH 键: ls -al ~/.ssh

  • 验证 SSH agent 是运行: ssh-添加 -l

  • 检查 remote URL: git remote -v

如何修复

  • Generate SSH 键: ssh-keygen -t ed25519 -C 'your_email@示例.com'

  • 添加键到 SSH agent: ssh-添加 ~/.ssh/id_ed25519

  • 添加公共键到 GitHub: 复制 ~/.ssh/id_ed25519.pub and 添加它 in GitHub 设置 > SSH 键

  • Or 切换到 HTTPS: git remote 设置-URL 原点 https://github.com/user/repo.git

如何预防

  • 设置 SSH 键当你首先配置 Git

  • 验证 SSH access 使用 ssh -T [email protected] 之前 cloning

相关资源

相关术语

相关课程

← 返回语言