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


当前回答

这就是答案。

设置github令牌:

https://github.com/settings/tokens

然后:

git remote set-url origin https://[token]@github.com/your_repository

其他回答

如果你刚刚启用了2FA:

修改。/git隐藏文件夹下的隐藏配置文件,如下所示:

[remote "origin"]
    url = https://username:PUT_YOUR_2FA_TOKEN_HERE@github.com/project/project.git

当使用https:// URL连接到远程存储库时,Git将不使用SSH作为身份验证,而是尝试通过HTTPS进行基本身份验证。通常,你只需要使用没有用户名的URL,例如https://github.com/username/repository.git,然后Git会提示你输入用户名(你的GitHub用户名)和密码。

如果您使用https://something@github.com/username/repository.git,那么您已经预设了Git将用于身份验证的用户名:某某。由于您使用https://git@github.com, Git将尝试使用Git用户名登录,当然您的密码是无效的。所以你必须使用你的用户名。

另一种方法实际上是使用SSH进行身份验证。这样你就不用一直输入密码了;既然它似乎已经起作用了,那就是你应该使用的。

要做到这一点,您需要更改远程URL,以便Git知道它需要通过SSH进行连接。格式如下:git@github.com:用户名/存储库。要更新你的URL,使用这个命令:

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

我只是关闭双因素认证,然后再试一次。这对我很管用。

试试这个:

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

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

更新旧的AD密码

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