GitHub: 用户名或密码无效
GitHub: invalid username or password
我在 GitHub 上托管了一个项目。尝试将我的修改推送到 master 时我失败了。我总是收到以下错误消息
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.
这似乎表明从那边看一切正常(eurydyce 是我的 github 用户名)。我严格遵循 github 上给出的说明和许多堆栈讨论的建议,但没有办法。你知道我做错了什么吗?
https://git@github.com/eurydyce/MDANSE.git 不是 ssh url,而是 https(需要您的 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
That's what I did in my ~/.gitconfig
file that contains currently the following entries [remote "origin"] url=git@github.com:eurydyce/MDANSE.git
这不应该在您的全局配置中(~/
中的那个)。
您可以在您的仓库中检查 git config -l
:url 应该在 local 配置中声明:<yourrepo>/.git/config
.
因此,请确保您在执行 git remote set-url
命令时位于回购路径中。
如Oliver's , an HTTPS URL would not use username/password if two-factor authentication (2FA)所述已激活。
在这种情况下,密码应为 PAT (personal access token) as seen in "Using a token on the command line"。
仅适用于 HTTPS URLS,SSH 不受此限制。
当使用 https://
URL 连接到您的远程存储库时,Git 将不会使用 SSH 作为身份验证,而是会尝试通过 HTTPS 进行基本身份验证。通常,您只需使用不带用户名的 URL,例如https://github.com/username/repository.git
,然后 Git 会提示您输入用户名(您的 GitHub 用户名)和密码。
如果您使用 https://something@github.com/username/repository.git
,则您已预设用户名 Git 将用于身份验证:something
。由于您使用 https://git@github.com
,Git 将尝试使用 git
用户名登录,您的密码当然无法使用该用户名。因此,您将不得不使用 您的 用户名。
替代方法实际上是使用 SSH 进行身份验证。这样你就不用一直输入密码了;因为它似乎已经起作用了,所以这就是你应该使用的。
为此,您需要更改遥控器 URL,因此 Git 知道它需要通过 SSH 连接。格式是这样的:git@github.com:username/repository
。要更新您的 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/'
为什么会这样
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.
如何修复
- 生成一个Personal Access Token. (Detailed guide on Creating a personal access token for the command line.)
- 复制个人访问令牌。
- Re-attempt 您正在尝试的命令并使用个人访问令牌代替您的密码。
相关问题:
再次尝试将其推送到您的分支。这将再次询问您的用户名和密码,因此您可以输入更改后的密码。这样您的新密码将再次存储在缓存中。
If like me you just updated your password and ran git push
to run into this issue, then there's a super easy fix.
仅限 Mac 用户。您需要删除 GitHub 的 OSX 钥匙串访问条目。您可以通过终端 运行 执行以下命令来完成此操作。
正在通过命令行删除您的凭据
通过命令行,您可以直接使用凭据助手来擦除钥匙串条目。
为此,请键入以下命令:
git credential-osxkeychain erase
host=github.com
protocol=https
# [Now Press Return]
如果成功,则不会打印任何内容。要测试它是否有效,请再次尝试从 GitHub 或 运行 克隆存储库,就像我的情况 git push
一样。如果系统提示您输入密码,则钥匙串条目已被删除。
您可能会收到此错误消息,因为您更新了密码。因此,在终端上首先确保您从钥匙串中清除 GitHub 凭据,然后将您的更改推送到您的存储库,终端将询问您的用户名和密码。
如果您在这种情况下收到此错误消息:
- 使用git企业中心
- 在git配置
中使用credential.helper=wincred
- 使用您最近windows 凭据更改
再看看这个回答:
Windows 将凭据存储在凭据管理器中,清除它或更新它。
解决步骤:
- 控制面板
- 凭证管理器
- 单击 Windows 凭据
- 在通用凭据部分,会有 git url,更新用户名和密码
- 重新启动 Git Bash 并尝试克隆
在 github 处禁用 2 因素身份验证对我有用。
我看到有一个被删除的答案是这样说的,删除原因是"does not answer the question"。如果它有效,那么我认为它回答了这个问题...
无需依赖生成 个人访问令牌 然后尝试使用 个人访问令牌 代替您的密码。
快速修复是将您的遥控器 URL 设置为指向 ssh
而不是 https
。
这样做git remote set-url origin git@github.com:username/repository
这个解决方案对我有用:
- 打开控制面板
- 转到凭据管理器
- 单击 Window 凭据
- 在通用凭据部分,会有 git url,更新用户名和密码
- 重新启动 Git Bash 并尝试克隆
- 控制面板
- 凭证管理器
- 寻找选项 webcredentials 和 windows credentials
- 在任何一个中你都会发现 git集线器凭据用正确的凭据修复它
- 打开 git 的新实例 bash 您应该能够执行 git 命令。
这对我有用,我能够拉入和推入我的远程仓库。
代替git pull
也试试git pull origin master
我修改了密码,第一条命令报错:
$ git pull
remote: Invalid username or password.
fatal: Authentication failed for ...
在 git pull origin master
之后,它要求输入密码并且似乎会自行更新
我只是禁用 Two-factor 身份验证并重试。它对我有用。
我遇到了同样的问题。我通过在客户端应用程序的回购设置中将远程分支的路径从 https://github.com/YourName/RepoName
更改为 git@github.com:YourName/RepoName.git
来解决它。
由于您可能希望为您的帐户启用 2FA,您可以设置一个 ssh 密钥,这样您就不需要在每次要将工作推送到 Github。
您可以在 documentation 中找到所有 ssh 设置步骤。首先,确保您目前没有任何 ssh 密钥(id_rsa.pub,等等)与 $ ls -al ~/.ssh
我在从 bitbucket 克隆应用程序时得到这个:
Cloning into 'YourAppName'...
Password for 'https://youruser id':
remote: Invalid username or password
我解决了。在这里您需要为您的用户名创建密码
单击您的个人资料和设置
然后创建应用密码选择你的名字密码将生成,将该密码粘贴到终端
我做到了:
$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
隐藏文件夹中的隐藏config
文件如下:
[remote "origin"]
url = https://username:PUT_YOUR_2FA_TOKEN_HERE@github.com/project/project.git
Windows 使用 cmd-Greetings
时出现问题
Windows 使用 cmd-Greetings 时出现问题,不允许您克隆私有存储库。删除本文档中描述的命令问候语(关键字 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 已启用并出现远程错误:用户名或密码无效。
致命:
的身份验证失败
如果您在 GitHub 中设置了 2FA,您将需要输入个人访问令牌而不是 2FA 代码和您的 GitHub 密码。
如何修复
- https://github.com/settings/tokens 生成的令牌
- 复制个人访问令牌
- 现在在 git 操作期间输入个人访问令牌代替您的密码
运行 在命令下方,以及在每次推拉之后,它都会要求您输入用户名和密码。
git config credential.helper ""
现在当您 pull/push 时,系统会要求您提供 git 凭据。天气你 运行 通过命令提示符或 Intellij Git.
最好最简单的方法之一
- 刚刚在 github
上禁用双向身份验证
- 转到控制面板--> windows 凭据--> 单击添加通用凭据
只需手动输入
添加 Github 的 URL:hhtps://www.github.com
用户名:您的用户名
密码:你的密码
然后保存到它
3) 因此在使用 git 推送命令时,您必须需要在 Github 上生成令牌,然后返回 Github > 设置 > 开发人员设置>生成令牌
希望这会有所帮助....
我通过安装 GitHub CLI 和 运行 gh auth login
解决了我的问题
我在 GitHub 上托管了一个项目。尝试将我的修改推送到 master 时我失败了。我总是收到以下错误消息
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.
这似乎表明从那边看一切正常(eurydyce 是我的 github 用户名)。我严格遵循 github 上给出的说明和许多堆栈讨论的建议,但没有办法。你知道我做错了什么吗?
https://git@github.com/eurydyce/MDANSE.git 不是 ssh url,而是 https(需要您的 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
That's what I did in my
~/.gitconfig
file that contains currently the following entries[remote "origin"] url=git@github.com:eurydyce/MDANSE.git
这不应该在您的全局配置中(~/
中的那个)。
您可以在您的仓库中检查 git config -l
:url 应该在 local 配置中声明:<yourrepo>/.git/config
.
因此,请确保您在执行 git remote set-url
命令时位于回购路径中。
如Oliver's
在这种情况下,密码应为 PAT (personal access token) as seen in "Using a token on the command line"。
仅适用于 HTTPS URLS,SSH 不受此限制。
当使用 https://
URL 连接到您的远程存储库时,Git 将不会使用 SSH 作为身份验证,而是会尝试通过 HTTPS 进行基本身份验证。通常,您只需使用不带用户名的 URL,例如https://github.com/username/repository.git
,然后 Git 会提示您输入用户名(您的 GitHub 用户名)和密码。
如果您使用 https://something@github.com/username/repository.git
,则您已预设用户名 Git 将用于身份验证:something
。由于您使用 https://git@github.com
,Git 将尝试使用 git
用户名登录,您的密码当然无法使用该用户名。因此,您将不得不使用 您的 用户名。
替代方法实际上是使用 SSH 进行身份验证。这样你就不用一直输入密码了;因为它似乎已经起作用了,所以这就是你应该使用的。
为此,您需要更改遥控器 URL,因此 Git 知道它需要通过 SSH 连接。格式是这样的:git@github.com:username/repository
。要更新您的 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/'
为什么会这样
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
orgit 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.
如何修复
- 生成一个Personal Access Token. (Detailed guide on Creating a personal access token for the command line.)
- 复制个人访问令牌。
- Re-attempt 您正在尝试的命令并使用个人访问令牌代替您的密码。
相关问题:
再次尝试将其推送到您的分支。这将再次询问您的用户名和密码,因此您可以输入更改后的密码。这样您的新密码将再次存储在缓存中。
If like me you just updated your password and ran
git push
to run into this issue, then there's a super easy fix.
仅限 Mac 用户。您需要删除 GitHub 的 OSX 钥匙串访问条目。您可以通过终端 运行 执行以下命令来完成此操作。
正在通过命令行删除您的凭据
通过命令行,您可以直接使用凭据助手来擦除钥匙串条目。
为此,请键入以下命令:
git credential-osxkeychain erase
host=github.com
protocol=https
# [Now Press Return]
如果成功,则不会打印任何内容。要测试它是否有效,请再次尝试从 GitHub 或 运行 克隆存储库,就像我的情况 git push
一样。如果系统提示您输入密码,则钥匙串条目已被删除。
您可能会收到此错误消息,因为您更新了密码。因此,在终端上首先确保您从钥匙串中清除 GitHub 凭据,然后将您的更改推送到您的存储库,终端将询问您的用户名和密码。
如果您在这种情况下收到此错误消息:
- 使用git企业中心
- 在git配置 中使用credential.helper=wincred
- 使用您最近windows 凭据更改
再看看这个回答:
Windows 将凭据存储在凭据管理器中,清除它或更新它。
解决步骤:
- 控制面板
- 凭证管理器
- 单击 Windows 凭据
- 在通用凭据部分,会有 git url,更新用户名和密码
- 重新启动 Git Bash 并尝试克隆
在 github 处禁用 2 因素身份验证对我有用。
我看到有一个被删除的答案是这样说的,删除原因是"does not answer the question"。如果它有效,那么我认为它回答了这个问题...
无需依赖生成 个人访问令牌 然后尝试使用 个人访问令牌 代替您的密码。
快速修复是将您的遥控器 URL 设置为指向 ssh
而不是 https
。
这样做git remote set-url origin git@github.com:username/repository
这个解决方案对我有用:
- 打开控制面板
- 转到凭据管理器
- 单击 Window 凭据
- 在通用凭据部分,会有 git url,更新用户名和密码
- 重新启动 Git Bash 并尝试克隆
- 控制面板
- 凭证管理器
- 寻找选项 webcredentials 和 windows credentials
- 在任何一个中你都会发现 git集线器凭据用正确的凭据修复它
- 打开 git 的新实例 bash 您应该能够执行 git 命令。
这对我有用,我能够拉入和推入我的远程仓库。
代替git pull
也试试git pull origin master
我修改了密码,第一条命令报错:
$ git pull
remote: Invalid username or password.
fatal: Authentication failed for ...
在 git pull origin master
之后,它要求输入密码并且似乎会自行更新
我只是禁用 Two-factor 身份验证并重试。它对我有用。
我遇到了同样的问题。我通过在客户端应用程序的回购设置中将远程分支的路径从 https://github.com/YourName/RepoName
更改为 git@github.com:YourName/RepoName.git
来解决它。
由于您可能希望为您的帐户启用 2FA,您可以设置一个 ssh 密钥,这样您就不需要在每次要将工作推送到 Github。
您可以在 documentation 中找到所有 ssh 设置步骤。首先,确保您目前没有任何 ssh 密钥(id_rsa.pub,等等)与 $ ls -al ~/.ssh
我在从 bitbucket 克隆应用程序时得到这个:
Cloning into 'YourAppName'...
Password for 'https://youruser id':
remote: Invalid username or password
我解决了。在这里您需要为您的用户名创建密码
单击您的个人资料和设置
然后创建应用密码选择你的名字密码将生成,将该密码粘贴到终端
我做到了:
$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
隐藏文件夹中的隐藏config
文件如下:
[remote "origin"]
url = https://username:PUT_YOUR_2FA_TOKEN_HERE@github.com/project/project.git
Windows 使用 cmd-Greetings
时出现问题Windows 使用 cmd-Greetings 时出现问题,不允许您克隆私有存储库。删除本文档中描述的命令问候语(关键字 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 已启用并出现远程错误:用户名或密码无效。 致命:
的身份验证失败如果您在 GitHub 中设置了 2FA,您将需要输入个人访问令牌而不是 2FA 代码和您的 GitHub 密码。
如何修复
- https://github.com/settings/tokens 生成的令牌
- 复制个人访问令牌
- 现在在 git 操作期间输入个人访问令牌代替您的密码
运行 在命令下方,以及在每次推拉之后,它都会要求您输入用户名和密码。
git config credential.helper ""
现在当您 pull/push 时,系统会要求您提供 git 凭据。天气你 运行 通过命令提示符或 Intellij Git.
最好最简单的方法之一
- 刚刚在 github 上禁用双向身份验证
- 转到控制面板--> windows 凭据--> 单击添加通用凭据
只需手动输入 添加 Github 的 URL:hhtps://www.github.com 用户名:您的用户名 密码:你的密码 然后保存到它
3) 因此在使用 git 推送命令时,您必须需要在 Github 上生成令牌,然后返回 Github > 设置 > 开发人员设置>生成令牌
希望这会有所帮助....
我通过安装 GitHub CLI 和 运行 gh auth login