#遇到问题的现象描述
在使用 Git 提交代码时,执行 git push origin main 命令报错,提示“remote: Permission denied (publickey)”,但我的 SSH 密钥已经配置过,且能正常通过 ssh -T git@github.com 测试连接。
#问题相关代码片段,运行结果,报错内容
git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 287 bytes | 287.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Permission denied (publickey).
fatal: unable to access 'https://github.com/user/repo.git/': The requested URL returned error: 403
#我的初步解答思路是
- 检查 SSH 密钥是否已添加到 SSH Agent:
ssh-add -l - 确认密钥是否正确绑定到 GitHub 账号(在 Settings → SSH and GPG keys 中查看)
- 尝试使用 HTTPS 方式重新推送,看是否与协议有关
#操作环境、软件版本等相关信息
- 操作系统:macOS Ventura 13.6
- Git 版本:git version 2.40.1
- GitHub 账号:已登录,SSH 密钥已上传
- 使用方式:终端命令行