You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 06:23:28