GitHub: invalid username or password

https://www.e-learn.cn/content/wangluowenzhang/299647

https://segmentfault.com/q/1010000000590947

problem:

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

Password for 'https://git@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://git@github.com/eurydyce/MDANSE.git/'

However, setting my ssh key to github seems ok. Indeed, when I do a ssh -T git@github.com I get

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?

Answer 1:

https://git@github.com/eurydyce/MDANSE.git is not an ssh url, it is an https one (which would require your GitHub account name, instead of 'git').

Try to use ssh://git@github.com:eurydyce/MDANSE.git or just git@github.com:eurydyce/MDANSE.git

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

The OP Pellegrini Eric adds:

That's what I did in my ~/.gitconfig file that contains currently the following entries [remote "origin"] url=git@github.com:eurydyce/MDANSE.git

This should not be in your global config (the one in ~/).
You could check git config -l in your repo: that url should be declared in the local config: /.git/config.

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

Answer 2:

After enabling Two Factor Authentication (2FA), you may see something like this when attempting to use git clonegit fetchgit pull or 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/'

Why this is happening

From the GitHub Help documentation:

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 clonegit fetchgit pull or 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.

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.

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

Answer 3:

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.

If you use https://something@github.com/username/repository.git, then you have preset the username Git will use for authentication: something. Since you used https://git@github.com, Git will try to log in using the git username for which your password of course doesn’t work. So you will have to use your username instead.

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.

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: git@github.com:username/repository. To update your URL use this command:

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

 

贴上中文翻译:

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

问题:

我有托管在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上的指示和许多栈讨论,但没有办法的建议。你有什么我可能做错了什么想法?

回答1:

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

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

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

这不应该是在全局配置(一中~/)。
您可以检查git config -l您的回购:该URL应在声明本地的配置:/.git/config

因此,请确保您在回购路径做时git remote set-url命令。
 

回答2:

实现双因素认证(2FA)后,您可能会看到这样的尝试时使用git clonegit fetchgit pullgit 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的帮助文档

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

...

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

如何修复

  1. 生成一个个人访问令牌。(详细的指南上创建用于命令行个人访问令牌。)
  2. 复制个人访问令牌。
  3. 重新尝试,你试图指挥和密码的地方使用个人访问令牌。

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

回答3:

当使用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。要更新您的网址使用这个命令:

git remote set-url origin git@github.com:username/repository
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值