Ubuntu环境下向Github推送代码遇远程权限错误求助
Github远程权限错误(403)解决方法
问题场景与报错信息
在Ubuntu系统推送代码到个人Github仓库时出现权限拒绝错误,核心操作及报错如下:
hamza@hamza-HP-EliteBook-840-G1:~/PycharmProjects/pythonProject/chat-website$ git push -u origin main remote: Permission to hamzaabialal/chat-website.git denied to hamzbialal. fatal: unable to access 'https://github.com/hamzaabialal/chat-website.git/': The requested URL returned error: 403
解决步骤
1. 修正Git账号配置
当前Git使用的账号hamzbialal无目标仓库hamzaabialal/chat-website的推送权限,先检查当前账号信息:
git config user.name git config user.email
如果输出不是仓库所属的hamzaabialal,修改全局配置(去掉--global可仅修改当前仓库):
git config --global user.name "hamzaabialal" git config --global user.email "你的Github绑定邮箱"
2. 检查并更新远程仓库地址
确认远程仓库地址是否正确:
git remote -v
- 若使用HTTPS协议,重新设置正确地址:
git remote set-url origin https://github.com/hamzaabialal/chat-website.git - 若使用SSH协议(需提前在Github后台添加本地SSH公钥),切换为SSH地址:
git remote set-url origin git@github.com:hamzaabialal/chat-website.git
3. 清除旧凭证缓存(HTTPS协议适用)
Ubuntu下Git可能缓存了旧账号的凭证,执行命令重置:
git config --global credential.helper libsecret
重新推送时,会提示输入Github用户名和个人访问令牌(Github已禁用密码登录HTTPS,需在账号设置中生成令牌)。
4. 修复上游分支关联问题
先取消无效的上游分支关联:
git branch --unset-upstream
再重新设置上游并推送:
git push -u origin main
内容的提问来源于stack exchange,提问作者Hamza Bilal
相关产品推荐
相关产品推荐

