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


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不受此限制。


当使用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

启用双因素身份验证(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 push就遇到了这个问题,那么有一个超级简单的解决方法。

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

通过命令行删除凭据

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

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

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

# [Now Press Return]

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


您可能会得到这个错误,因为您已经更新了密码。所以在终端上,首先确保你从钥匙链中清除你的GitHub凭证,然后将你的更改推到你的回购,终端将要求你的用户名和密码。


在这种情况下,如果你得到这个错误信息:

使用github创业 使用凭据。在git配置中,Helper =wincred 使用您最近更改的Windows凭据

然后看看这个答案: https://stackoverflow.com/a/39608906/521257

Windows将凭据存储在凭据管理器中,清除或更新它。


解决步骤:

控制面板 证书管理器 单击Windows凭证 在Generic Credential部分,将有git url,更新用户名和密码 重新启动Git Bash并尝试克隆

注意: 如果你在通用凭据部分没有找到git url,请遵循下面的答案 https://stackoverflow.com/a/55858690/7372432


在github上禁用2因素身份验证对我有用。

我看到有一个删除的答案是这样说的,删除的原因是“没有回答这个问题”。如果它有效,那么我认为它回答了这个问题……


不需要依赖于生成个人访问令牌,然后尝试使用个人访问令牌在您的密码的地方。

快速修复方法是将远程URL设置为指向ssh而不是https。

这个git远程设置url来源git@github.com:用户名/存储库


这个解决方案对我很有效:

打开控制面板 转到凭证管理器 单击窗口凭据 在Generic Credential部分,将有git url,更新用户名和密码 重新启动Git Bash并尝试克隆


控制面板 证书管理器 寻找选项web凭据和windows凭据 在任何一个你会发现github凭证修复它与正确的凭证 打开新的git bash实例,你应该能够执行你的git命令。

这为我工作,我能够拉和推到我的远程回购。


而不是git拉也尝试git拉origin master

我修改了密码,第一个命令报错:

$ git pull
remote: Invalid username or password.
fatal: Authentication failed for ...

git拉了origin master后,它询问密码,似乎更新了自己


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


我也有同样的问题。我通过在客户端应用程序的repo设置中将远程分支的路径从https://github.com/YourName/RepoName更改为git@github.com:YourName/RepoName.git来解决这个问题。


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

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


我从bitbucket克隆应用程序时得到这个:

Cloning into 'YourAppName'...
Password for 'https://youruser id': 
remote: Invalid username or password

我解出来了。在这里,您需要为您的userid创建密码

点击你的个人资料和设置 然后创建应用密码选择你的名字密码将生成,粘贴该密码到终端


我做了:

$git pull origin master

然后它要求[用户名]和[密码],现在似乎工作正常。


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


试试这个:

# 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

如果你刚刚启用了2FA:

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

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

Windows使用cmd-Greetings时出现问题

在Windows上使用cmd-Greetings不允许克隆私有存储库有一个问题。删除本文档中描述的cmd-greeting(关键字Command Processor):

已知的问题

我可以确认其他客户,如SourceTree, GitKraken, Tower和TortoiseGit也受到了这个问题的影响。


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

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运行。


我通过安装GitHub CLI并运行gh auth登录来解决我的问题

看到的: https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git#github-cli


这种情况发生的原因有很多。在我的案例中,没有一个解决方案有效。特别是,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.


我也有同样的问题

$ git clone https://github.com/sample-url.git
Cloning into 'Project'...
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/sample-url.git/'

我只是git init,然后git clone <clone-url>

git init
git clone https://github.com/your-clone-Url

这对我很管用。


这就是答案。

设置github令牌:

https://github.com/settings/tokens

然后:

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

当我遇到这个问题时,我所做的解决方法是从我的github仪表板生成新的令牌,并将以下代码粘贴到我的终端

$ git远程设置url来源https://your-github-username:your-github-token@github.com/your-github-username/your-github-repo.git