我有一个项目托管在GitHub上。我失败时,试图推动我的修改在主人。我总是得到以下错误消息

Password for 'https://git@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://git@github.com/eurydyce/MDANSE.git/'

但是,设置我的ssh密钥到github似乎没问题。实际上,当我执行ssh -T git@github.com时,我得到

Hi eurydyce! You've successfully authenticated, but GitHub does not provide shell access.

这似乎表明,一切都是OK从这一边(eurydyce是我的github用户名)。我严格按照github上给出的说明和许多堆栈讨论的建议,但没有办法。你知道我可能做错了什么吗?


当前回答

因为你可能想让你的账户启用2FA,你可以设置一个ssh密钥,这样你就不需要每次你想把工作推送到Github时都输入你的Github凭据。

您可以在文档中找到所有的ssh设置步骤。首先,确保当前没有任何ssh密钥(id_rsa. exe)。Pub,等等)使用$ ls -al ~/.ssh

其他回答

启用双因素身份验证(2FA)后,当你尝试使用git clone、git fetch、git pull或git push时,你可能会看到类似这样的东西:

$ git push origin master
Username for 'https://github.com': your_user_name
Password for 'https://your_user_name@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/your_user_name/repo_name.git/'

为什么会发生这种情况

从GitHub帮助文档:

After 2FA is enabled you will need to enter a personal access token instead of a 2FA code and your GitHub password. ... For example, when you access a repository using Git on the command line using commands like git clone, git fetch, git pull or git push with HTTPS URLs, you must provide your GitHub username and your personal access token when prompted for a username and password. The command line prompt won't specify that you should enter your personal access token when it asks for your password.

如何解决

生成一个个人访问令牌。(关于为命令行创建个人访问令牌的详细指南。) 复制个人访问令牌。 重新尝试您正在尝试的命令,并使用个人访问令牌代替您的密码。

相关问题: https://stackoverflow.com/a/21374369/101662

我已经成功地使用以下命令。

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

试着告诉我这些对你是否有效。

启用2FA,并得到错误远程:无效的用户名或密码。 fatal:认证失败

如果你在GitHub中启用了2FA,你需要输入一个个人访问令牌,而不是2FA代码和你的GitHub密码。

如何解决

https://github.com/settings/tokens生成令牌 复制个人访问令牌 现在在git操作期间输入个人访问令牌在您的密码的地方

运行下面的命令,然后在每一次推拉之后,它会要求你输入用户名和密码。

  git config credential.helper ""

现在当你拉/推你将被要求git凭证。不管你是通过命令提示符还是Intellij Git运行。

如果你像我一样刚刚更新了密码,然后运行git push就遇到了这个问题,那么有一个超级简单的解决方法。

仅限Mac用户使用。您需要删除GitHub的OSX Keychain访问条目。您可以通过终端运行以下命令来完成。

通过命令行删除凭据

通过命令行,可以直接使用凭据帮助程序擦除密钥链条目。

要做到这一点,键入以下命令:

git credential-osxkeychain erase
host=github.com
protocol=https

# [Now Press Return]

如果它成功了,什么也不会打印出来。为了测试它的工作,试着从GitHub克隆一个存储库,或者像我的情况下git push一样再次运行之前的操作。如果提示输入密码,则该keychain条目已被删除。