我有一个项目托管在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上给出的说明和许多堆栈讨论的建议,但没有办法。你知道我可能做错了什么吗?


当前回答

由于密码错误,有时会发生这种问题。请检查您是否连接了AD密码(Active Directory密码),并且您最近更改了AD密码,但仍在使用旧密码尝试git命令。

更新旧的AD密码

Control Panel > Credential Manager > Windows Credential > change github password with my new AD password

其他回答

试试这个:

# git remote set-url origin git@github.com:username/repository

我经常遇到这个问题。 确保你设置了git——config user.name ""而不是你的真实姓名,我已经做过几次了。

https://git@github.com/eurydyce/MDANSE.git不是ssh url,而是https url(这需要你的GitHub账户名,而不是'git')。

尝试使用ssh://git@github.com:eurydyce/MDANSE.git或直接使用git@github.com:eurydyce/MDANSE.git

git remote set-url origin git@github.com:eurydyce/MDANSE.git

OP Pellegrini Eric补充道:

这就是我在~/中所做的。当前包含以下条目的gitconfig文件[remote "origin"] url=git@github.com:eurydyce/MDANSE.git

它不应该在你的全局配置中(在~/中的那个)。 你可以在你的repo中检查git config -l: url应该在本地配置中声明:<yourrepo>/.git/config。

因此,在执行git remote set-url命令时,请确保您处于repo路径中。


正如Oliver的回答中提到的,如果激活了双因素身份验证(2FA), HTTPS URL将不使用用户名/密码。

在这种情况下,密码应该是PAT(个人访问令牌),见“在命令行上使用令牌”。

此限制仅适用于HTTPS url, SSH不受此限制。

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

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

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

这种情况发生的原因有很多。在我的案例中,没有一个解决方案有效。特别是,git拉origin master没有问我我的用户名和密码。

我在Windows上的github密码最近改了。我使用凭据管理器来管理我的密码。以下是对我有效的方法:

Confirm you are using the credential manager for git: git config --list … credential.helper=manager Run a new command prompt as administrator List all stored credential with cmdkey /list from C:\WINDOWS\system32> Remove the github target with cmdkey /delete:<target name>. In my case, the target name was github.<companyname>.com Open a new prompt and run a git command. You should get a popup asking for your usernmame and password. After providing the new credentials, it won't ask you for it again.