git GitHub:无效的用户名或密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29297154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:02:43  来源:igfitidea点击:

GitHub: invalid username or password

gitgithub

提问by Eurydice

I have a project hosted on GitHub. I fail when trying to push my modifications on the master. I always get the following error message

我在 GitHub 上托管了一个项目。尝试将我的修改推送到主服务器时失败了。我总是收到以下错误消息

Password for 'https://[email protected]': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://[email protected]/eurydyce/MDANSE.git/'

However, setting my ssh key to github seems ok. Indeed, when I do a ssh -T [email protected]I get

但是,将我的 ssh 密钥设置为 github 似乎没问题。事实上,当我做一个ssh -T [email protected]我得到

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

Which seems to indicate that everything is OK from that side (eurydyce being my github username). I strictly followed the instructions given on github and the recommendations of many stack discussion but no way. Would you have any idea of what I may have done wrong?

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

采纳答案by VonC

https://[email protected]/eurydyce/MDANSE.gitis not an ssh url, it is an https one (which would require your GitHub account name, instead of 'git').

https://[email protected]/eurydyce/MDANSE.git不是 ssh 网址,而是 https 网址(需要您的 GitHub 帐户名,而不是“ git”)。

Try to use ssh://[email protected]:eurydyce/MDANSE.gitor just [email protected]:eurydyce/MDANSE.git

尝试使用ssh://[email protected]:eurydyce/MDANSE.git或只是[email protected]:eurydyce/MDANSE.git

git remote set-url origin [email protected]:eurydyce/MDANSE.git

The OP Pellegrini Ericadds:

OP佩莱格里尼埃里克补充说:

That's what I did in my ~/.gitconfigfile that contains currently the following entries [remote "origin"] [email protected]:eurydyce/MDANSE.git

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

This should not be in your global config (the one in ~/).
You could check git config -lin your repo: that url should be declared in the localconfig: <yourrepo>/.git/config.

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

So make sure you are in the repo path when doing the git remote set-urlcommand.

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



As noted in Oliver's answer, an HTTPS URL would not use username/password if two-factor authentication (2FA)is activated.

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

In that case, the password should be a PAT (personal access token)as seen in "Using a token on the command line".

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

That applies only for HTTPS URLS, SSH is not affected by this limitation.

这仅适用于 HTTPS URL,SSH 不受此限制的影响。

回答by Oliver

After enabling Two Factor Authentication (2FA), you may see something like this when attempting to use git clone, git fetch, git pullor git push:

实现双因素认证(2FA)后,您可能会看到这样的事情在尝试使用时git clonegit fetchgit pullgit push

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

Why this is happening

为什么会发生这种情况

From the GitHub Help documentation:

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 pullor git pushwith 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.

启用 2FA 后,您需要输入个人访问令牌而不是 2FA 代码和您的 GitHub 密码。

...

例如,当您访问使用类似的命令在命令行中使用Git存储库git clonegit fetchgit pullgit push使用HTTPS URL,则必须提供您的GitHub用户名和当系统提示输入用户名和密码令牌您的个人访问。命令行提示符不会指定您在询问密码时应输入个人访问令牌。

How to fix it

如何修复

  1. Generate a Personal Access Token. (Detailed guide on Creating a personal access token for the command line.)
  2. Copy the Personal Access Token.
  3. Re-attempt the command you were trying and use Personal Access Token in the place of your password.
  1. 生成个人访问令牌。(有关为命令行创建个人访问令牌的详细指南。)
  2. 复制个人访问令牌。
  3. 重新尝试您尝试的命令并使用个人访问令牌代替您的密码。

Related question: https://stackoverflow.com/a/21374369/101662

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

回答by amoljdv06

Solution steps:

解决步骤:

  1. Control Panel
  2. Credential Manager
  3. Click Window Credentials
  4. In Generic Credential section ,there would be git url, update username and password
  5. Restart Git Bash and try for clone
  1. 控制面板
  2. 凭证管理器
  3. 单击窗口凭据
  4. 在 Generic Credential 部分,会有 git url,更新用户名和密码
  5. 重新启动 Git Bash 并尝试克隆

回答by Ahmad Awais

If like me you just updated your password and ran git pushto run into this issue, then there's a super easy fix.

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

For Mac users only. You need to delete your OSX Keychain access entries for GitHub. You can do it via terminal by running the following commands.

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

Deleting your credentials via the command line

通过命令行删除您的凭据

Through the command line, you can use the credential helper directly to erase the keychain entry.

通过命令行,您可以直接使用凭证助手来擦除钥匙串条目。

To do this, type the following command:

为此,请键入以下命令:

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

# [Now Press Return]

If it's successful, nothing will print out. To test that it works, try and clone a repository from GitHub or run your previous action again like in my case git push. If you are prompted for a password, the keychain entry was deleted.

如果成功,则不会打印任何内容。要测试它是否有效,请尝试从 GitHub 克隆一个存储库,或者像我的情况一样再次运行您之前的操作git push。如果系统提示您输入密码,则钥匙串条目已被删除。

回答by poke

When using the https://URL to connect to your remote repository, then Git will not use SSH as authentication but will instead try a basic authentication over HTTPS. Usually, you would just use the URL without a username, e.g. https://github.com/username/repository.git, and Git would then prompt you to enter both a username (your GitHub username) and your password.

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

If you use https://[email protected]/username/repository.git, then you have preset the username Git will use for authentication: something. Since you used https://[email protected], Git will try to log in using the gitusername for which your password of course doesn't work. So you will have to use yourusername instead.

如果您使用https://[email protected]/username/repository.git,那么您已经预设了 Git 将用于身份验证的用户名:something。由于您使用了https://[email protected],Git 将尝试使用git您的密码当然不起作用的用户名登录。因此,您将不得不改用您的用户名。

The alternative is actually to use SSH for authentication. That way you will avoid having to type your password all the time; and since it already seems to work, that's what you should be using.

替代方法实际上是使用 SSH 进行身份验证。这样您就不必一直输入密码;并且由于它似乎已经起作用了,这就是您应该使用的。

To do that, you need to change your remote URL though, so Git knows that it needs to connect via SSH. The format is then this: [email protected]:username/repository. To update your URL use this command:

为此,您需要更改远程 URL,因此 Git 知道它需要通过 SSH 进行连接。格式是这样的:[email protected]:username/repository. 要更新您的 URL,请使用以下命令:

git remote set-url origin [email protected]:username/repository

回答by Shiva Rajkumar

just try to push it to your branch again. This will ask your username and password again, so you can feed in the changed password. So that your new password will be stored again in the cache.

只需尝试再次将其推送到您的分支。这将再次询问您的用户名和密码,因此您可以输入更改后的密码。这样您的新密码将再次存储在缓存中。

回答by Paul

Instead of git pullalso try git pull origin master

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

I changed password, and the first command gave error:

我更改了密码,第一个命令出错:

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

After git pull origin master, it asked for password and seemed to update itself

之后git pull origin master,它要求输入密码并且似乎在自我更新

回答by Divyanshu Rawat

No need to rely on Generating a Personal Access Tokenand then trying and use Personal Access Tokenin the place of your password.

无需依赖生成个人访问令牌,然后尝试使用个人访问令牌代替您的密码。

Quick fix is to set your remote URL to point to sshnot https.

快速修复是将您的远程 URL 设置为指向sshnot https

Do this git remote set-url origin [email protected]:username/repository

做这个 git remote set-url origin [email protected]:username/repository

回答by prachit

I am getting this while cloning app from bitbucket:

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

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

I solved it. Here you need to create password for your userid

我解决了。在这里您需要为您的用户 ID 创建密码

  1. Click on Your profile and settings Click on Your profile and settings

  2. Then Create app password choose your name password will generated ,paste that password to terminal Create app password

  1. 单击您的个人资料和设置 单击您的个人资料和设置

  2. 然后创建应用程序密码选择您的名称密码将生成,将该密码粘贴到终端 创建应用密码

回答by ZaMy

I did:

我做了:

$git pull origin master

Then it asked for the [Username] & [Password] and it seems to be working fine now.

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