[Solution] Github Permission denied (publickey)

出现 "Permission denied (publickey)" 说明本地 SSH 公钥没被 GitHub 认可或没被 ssh-agent 使用。

按步骤排查(在 Git Bash):

  1. 检查是否已有密钥
bash 复制代码
ls ~/.ssh
# 常见文件:id_ed25519 / id_rsa 及对应 .pub
  1. 如无密钥则生成(推荐 ed25519)
bash 复制代码
ssh-keygen -t ed25519 -C "你的邮箱"
# 一路回车,生成 ~/.ssh/id_ed25519 和 id_ed25519.pub
  1. 启动 ssh-agent 并添加私钥
bash 复制代码
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
  1. 把公钥加入 GitHub
bash 复制代码
cat ~/.ssh/id_ed25519.pub

复制输出,在 GitHub → Settings → SSH and GPG keys → New SSH key 粘贴保存。

  1. 测试连接

  2. 再次推送

成功*★,°*:.☆( ̄▽ ̄)/.°★* 。

tips: 如果 ssh-add 报错或重启后失效,可在当前会话先执行 eval "$(ssh-agent -s)"ssh-add

相关推荐
一袋米扛几楼984 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
尘埃落定wf5 小时前
# GitHub CLI:告别繁琐的 Git 命令,让开发更高效
git·github
zh_xuan5 小时前
上传api调试工具到github
github
AIMath~7 小时前
彻底删除 GitHub 仓库中特定文件夹的完整指南
github
DogDaoDao8 小时前
【GitHub】OpenClaw:开源个人AI助手的新标杆
人工智能·深度学习·开源·大模型·github·ai编程·opeclaw
一点一木16 小时前
🚀 2026 年 4 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
宝桥南山18 小时前
AI - 在命令行中尝试一下ACP(Agent Client Protocol)通信
microsoft·微软·github·aigc·copilot
拾贰_C21 小时前
【Github | GitHub Copilot | 学生认证】 GitHub Copilot学生如何认证
github
旅之灵夫1 天前
【GitHub项目推荐--OpenArm:开源7自由度仿人机械臂平台】
github
一乐小哥1 天前
坚持迭代一个 Chrome 插件半年后,我的同事问我:"这不是 Chrome 自带的功能吗?"
chrome·github·ai编程