Git推送导致“身份验证失败”

在使用Git推送时遇到'Authentication Failed'错误。可能的原因包括:URL不正确、凭证存储问题、双因素身份验证冲突或者URL中包含'www'子域。解决方案包括:检查并使用正确的SSH或HTTPS URL,删除或更新.gitconfig中的凭证,生成个人访问令牌,或确保URL中不包含'www'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Git push results in “Authentication Failed”

I have been using Github for a little while and I have been fine with git add , git commit , and git push so far with no problems. 我已经使用Github一段时间了,我一直很好用git addgit commitgit push到目前为止没有任何问题。 Suddenly I am having an error that says: 我突然发现一个错误:

fatal: Authentication Failed 致命:身份验证失败

In the terminal I cloned a repository, worked on a file and then I used git add to add the file to the commit log and when I did git commit , it worked fine. 在终端我克隆了一个存储库,处理了一个文件,然后我使用git add将文件git add到提交日志中,当我执行git commit ,它运行正常。 Finally, git push asks for username and password. 最后, git push要求输入用户名和密码。 I put those in correctly and every time I do this, it says the same error. 我正确地把它们放进去,每次我这样做,它都说同样的错误。

Does anyone have any idea what the cause of this problem is and how I can fix it? 有谁知道这个问题的原因是什么以及我如何解决它?

The contents of .git/config are: .git/config的内容是:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = http://www.github.com/######/Random-Python-Tests
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        name = #####
        email = ############

#1楼

参考:https://stackoom.com/question/1C5xu/Git推送导致-身份验证失败


#2楼

First, you can make sure to use the proper url: 首先,您可以确保使用正确的URL:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

Then, if it was working before, and if it wasn't asking for you username, it must be because you had stored your credentials (login/password) in a $HOME/.netrc file, as explained here . 然后,如果它之前正在工作,并且如果它没有要求您使用用户名,则必须是因为您已将凭证(登录/密码)存储在$HOME/.netrc文件中,如此处所述 You can double-check those settings, and make sure that your proxy, if you have one, hasn't changed. 您可以仔细检查这些设置,并确保您的代理(如果有的话)没有更改。

If that still doesn't work, you can switch to an ssh url: 如果仍然无效,您可以切换到ssh网址:

git remote set-url origin git@github.com:zkirkland/Random-Python-Tests.git

But that means you have published your ssh public key in your Account settings . 但这意味着您已在帐户设置中发布了ssh公钥。


#3楼

I had the same problem. 我有同样的问题。 I set url in that way: 我以这种方式设置url:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

I also removed from config file this entry: askpass = /bin/echo . 我还从配置文件中删除了这个条目: askpass = /bin/echo Then "git push" asked me for username and password and this time it worked. 然后“git push”问我用户名和密码,这次它有效。


#4楼

If you enabled two-factor authentication in your Github account you won't be able to push via HTTPS using your accounts password. 如果您在Github帐户中启用了双因素身份验证,则无法使用您的帐户密码通过HTTPS推送。 Instead you need to generate a personal access token. 相反,您需要生成个人访问令牌。 This can be done in the application settings of your Github account. 这可以在您的Github帐户的应用程序设置中完成。 Using this token as your password should allow you to push to your remote repository via HTTPS. 使用此令牌作为密码应该允许您通过HTTPS推送到远程存储库。 Use your username as usual. 照常使用您的用户名。

https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/

You may also need to update the origin for your repository if set to https: 如果设置为https,您可能还需要更新存储库的源:

git remote -v 
git remote remove origin 
git remote add origin git@github.com:user/repo.git  

#5楼

I think that for some reason GitHub is expecting the URL to NOT have subdomain www. 我认为由于某种原因,GitHub期望URL不具有子域名www。 When I use (for example) 当我使用(例如)

git remote set-url origin https://www.github.com/name/repo.git

it gives the following messages: 它给出了以下消息:

remote: Anonymous access to name/repo.git denied
fatal: Authentication failed for https://www.github.com/name/repo.git

However, if I use 但是,如果我使用

git remote set-url origin https://github.com/name/repo.git

it works perfectly fine. 它工作得很好。 Doesn't make too much sense to me... but I guess remember not to put www in the remote URL for GitHub repositories. 对我来说没有多大意义......但我想记得不要把www放在GitHub存储库的远程URL中。

Also notice the clone URLs provided on the GitHub repository webpage doesn't include the www. 另请注意,GitHub存储库网页上提供的克隆URL不包含www。


#6楼

I'm not really sure what I did to get this error, but doing: 我不确定我做了什么来得到这个错误,但做的是:

git remote set-url origin https://...

didn't work for me. 不适合我。 However: 然而:

git remote set-url origin git@bitbucket.org:user/repo

somehow worked. 不知何故工作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值