提交到Git返回错误代码403致命错误:HTTP请求失败

819

我能够通过HTTPS认证克隆该存储库的一个副本。我已经提交了一些更改并希望将它们推送回GitHub服务器。在Windows 7 x64上使用Cygwin。

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
error: The requested URL returned error: 403 while accessing https://MichaelDrog
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

同时设置为详细模式。我仍然感到相当困惑。

C:\cygwin\home\XPherior\Code\lunch_call>set GIT_CURL_VERBOSE=1

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
< WWW-Authenticate: Basic realm="GitHub"
<
* Ignoring the response-body
* Expire cleared
* Connection #0 to host github.com left intact
* Issue another request to this URL: 'https://MichaelDrogalis@github.com/dereker
dmann/lunch_call.git/info/refs?service=git-receive-pack'
* Couldn't find host github.com in the _netrc file; using defaults
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (207.97.227.239) port 443 (#0)
* 0x23cb740 is at send pipe head!
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="GitHub"
* The requested URL returned error: 401
* Closing connection #0
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL re-using session ID
* SSL connection using AES256-SHA
* old SSL session ID is stale, removing
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs HTTP/1.1
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

* The requested URL returned error: 403
* Expire cleared
* Closing connection #0
error: The requested URL returned error: 403 while accessing https://MichaelDrog
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

以下是我所拥有的Git和Curl版本:

C:\Users\XPherior>git --version
git version 1.7.4.msysgit.0

C:\Users\XPherior>curl --version
curl 7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate Largefile NTLM SSL SSPI libz

4
看一下这条评论,应该发布为答案。我让它在1.7.1版本中工作了,也遇到了缺少用户/密码提示的问题。感谢 https://dev59.com/K2s05IYBdhLWcg3wG-VR#9575906 提供的帮助... - sjas
3
检查用户对仓库是否具有读写权限。 - Céline Aussourd
42
将来展示示例HTTP头时,请勿粘贴“Authorization: Basic <stuff>”。这很容易被Base64解码并获取您的密码。@Mike:如果您自发布此问题以来没有更改GitHub密码,建议您这样做。 - FlipMcF
6
谢谢,我不知道这个事情。已经更改了密码。 - Mike
8
@Mike 没问题。现在我可以毫不掩饰地宣传一下我写的博客:http://goo.gl/bpae94 - FlipMcF
显示剩余9条评论
75个回答

5

以上的答案都不能解决我的企业级 GitHub 账户问题。请按照以下步骤通过 ssh 密钥生成方式进行推送。

访问您的 git 账户创建一个仓库。

生成 ssh 密钥:

ssh-keygen -t rsa -C "your_email@example.com"

将文件~/.ssh/id_rsa.pub的内容复制到您GitHub账户设置中的SSH密钥中。 测试SSH密钥:

ssh -T git@github.com
clone the repo:
git clone git://github.com/username/your-repository

现在请进入您的 git 克隆文件夹并执行以下操作:
git remote set-url origin git@github.com:username/your-repository.git

现在尝试对文件进行编辑(可以尝试编辑README),然后执行以下操作:

git add -A
git commit -am "my update msg"
git push -u origin master

更新:新的Git版本似乎建议在创建新仓库时不要有任何文件。因此,请创建一个空白的仓库。

这个答案对我很有帮助,但是你必须确保你的密钥具有默认名称,如 id_rsaid_rsa.pub,否则,你将继续收到错误信息 Permission denied (publickey,keyboard-interactive). fatal: The remote end hung up unexpectedly。因此,要么将你的密钥重命名为默认名称,要么使用这个答案来澄清如何设置自定义路径到ssh密钥。 - Serhii Popov

5

当使用ssh(根据Xiao)或http URL时,如果遇到权限拒绝403错误,请尝试以下命令。

>git config --global --unset-all credential.helper

>git config --unset-all credential.helper

使用管理员权限

>git config --system --unset-all credential.helper

现在每次 Git 都会要求输入登录名和密码。通过 git config --global credential.helper store 命令保存它们。 - CoolMind

4

我的解决方法:

我的代码库是一个“分支”,仍然链接到父代码库。

git remote -v

会告诉你这是否是你的代码库。

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

该功能允许您重新配置您的仓库,然后允许您进行推送操作。


4
若在使用Github时遇到403错误,确保在创建令牌时勾选所有复选框:请访问https://github.com/settings/tokens。我认为Github的令牌生成页面设计存在缺陷。

4

我曾遇到类似的问题,但大部分答案都不能解决我的问题。我一直在收到“权限被拒绝403禁止”错误。以下步骤帮助我解决了这个问题:

如果你已经安装了brew,请使用以下命令安装git CLI:

brew install gh

参考安装 git 命令行界面:https://github.com/cli/cli#installation 然后运行:
gh auth login  

它会问你以下问题,回答如下:

What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

它将为您生成代码,输入生成的代码以使用浏览器进行身份验证。

! First copy your one-time code: 14*B-E2*7

Press Enter to open github.com in your browser... 
✓ Authentication complete.

通过遵循以上步骤,您将能够向您的代码库中推送代码。

3

请使用管理员权限尝试以下命令。这个命令解决了我的问题,希望它也能解决你的问题。

git config --system --unset-all credential.helper

这个命令会重置所有用户凭据,并让用户重新提供用户ID和令牌。对于我的情况,通过执行此操作解决了问题。我之前登录了另一个Git账户。 - Shihab Uddin

3

将用户名作为URL的一部分添加,这个错误是因为git命令使用http而不是https。所以请设置url。

git remote set-url origin https://<username>@github.com/Path_to_repo.git

之后会提示您输入密码:


3
对于任何好奇心的人,我的Mac电脑和Lucid虚拟机分别运行Git 1.7.6和1.7.0.4,完全相同的存储库可以从我的Mac(更新的Git)推送,但无法从VM推送。curl版本相同。也许一些旧版的Git不支持https推送?

是的,在这里可以将代码推送到Github(即使通过带密码的代理)。我使用的是Git 1.7.3。对我来说,它最初失败是因为我输入了错误的密码。 - guettli
10
对于我来说,在使用git 1.7.1时可以工作,但有一件事情你需要注意(这也是我第一次尝试时错过的):在HTTPS-URL中提供用户名,即 url=https://username@github.com/username/repo.git - lwho

2

2

我想出了自己的解决方法。

问题不在于将协议从https更改为ssl,而是设置Github的全局用户名和电子邮件!(我试图推送到一个私有仓库。)

git config --global user.email "your_github_email_@email.com"

git config --global user.name "Your full name"

对我不起作用。配置已设置,请使用 https://github.com/..,其中不要包含“@”。 - ses

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接