ChatGPT解决这个技术问题 Extra ChatGPT

GitHub: invalid username or password

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?

I'm not sure I should post an answer or not(high chance get downvote), since I solved this error message by changed the password in github settings after tried many attempts with the "correct"(check by inspect element) password.
Some organizations have SAML SSO enabled. In this case, best is to use personal access token. If you are already logged in, please re-login and give Github Desktop/Sourcetree permission

C
Community

After enabling Two Factor Authentication (2FA), you may see something like this when attempting to use git clone, git fetch, git 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 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.

How to fix it

Generate a Personal Access Token. (Detailed guide on Creating a personal access token for the command line.) Copy the Personal Access Token. 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


Kudo's and upvotes; the new token generation is what i needed. Also; the "Copy code" included additional (invalid) characters so I had to manually enter my .... 20[?] digit random key.
This was my issue, after adding 2 factor auth, which i suspected, however the documentation on this was lacking. Thanks for the answer!
@BeauSmith: That's way more substantive an edit than we normally allow. You basically completely rewrote this answer. Please post that as your own, separate answer instead. Also see What do you do if someone basically re-writes your whole answer?
Let's all please allow the decision to rollback or not to be decided by @Oliver here - there's a perfectly sound argument either way
Editor here… As it seems that people marking this answer as correct (like myself) arrive on this page for a problem which is slightly different than the asker intended, I was trying to add some "google juice" terms and make the answer more visually appealing such that others seeking this solution can find it. Trying to make things better for the community. 😀
V
VonC

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: <yourrepo>/.git/config.

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

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

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

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


oups ! You are right, making those changes in my local config made everything work. Thanks a lot.
Don't understand this answer at all
@Clo sure, what part is lacking clarity, how may I improve this answer?
When I did this (replacing the username and repo name with mine), I get "Permission denied (publickey)." I would like to log in with username and password if possible.
@byronaltice If this is SSH, that means you have a ~/.ssh/config or %USERPROFILE%\.ssh\config file, with a github.com entry in it.
S
Sabito 錆兎 stands with Ukraine

Solution steps:

Control Panel Credential Manager Click Windows Credentials In Generic Credential section ,there would be git url, update username and password Restart Git Bash and try for clone


I was having this problem with a company version of github (so using local username/password). This solution fixed it.
In new windowses, you can search for "Windows credentials" or similar in your language. It'll pop up a result and you can try this solution.
Perfect solution for on premises github, where companies obliges you to use https
I was following another thread to refresh the credentials, with no luck. You solution works perfectly
Same issue: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
A
Ahmad Awais

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

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.

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.


For windows: git credential-wincred erase host=github.com protocol=https
I encountered this problem on a BitBucket repo. This answer with host=bitbucket.org instead of GitHub fixed it for me.
I had changed my Github password after which git pull wasn't working for me. This worked for me.
That's the right answer in case someone get stuck after the last Github authentication update to enforce login with a username/token instead of username/password.
p
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.

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

when trying your command I get the following message warning: remote.origin.url has multiple values. This may be due to the fact that I already have an remote tag in my ~/.gitconfig file which contains the value [remote "origin"] url=git@github.com:eurydyce/MDANSE.git.
I've been searching for hours already on why I couldn't push my changes, and this answer finally gives a perfect explanation and helped me fix it, thanks!
P
Paul

Instead of git pull also try 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


This is what I needed!
This is the simplest way to do it and it works!
S
Sagar Jethi

2FA is enabled and getting error remote: Invalid username or password. fatal: Authentication failed for

If you set 2FA is enabled in GitHub you will need to enter a personal access token instead of a 2FA code and your GitHub password.

How to fix it

https://github.com/settings/tokens generated token Copy the Personal Access Token Now enter Personal Access Token in the place of your password during git operation


This was it! Could you explain what's going on here? Would I need the token for any Github related use from nowon?
After this, then follow @Anil_Reddy's answer.
S
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.


Not sure why this got a downvote. In my case my credentials had been updated, and the second git push prompted for the appropriate update, as this answer indicates.
Not sure, what you meant, it is not asking for new credentials executing git push origin master...
Nice! Same thing if you're trying to git clone something but it tells you your username/password are incorrect. If either have recently changed, just run git clone <myprojecturl> again and this time it will ask you to re-enter your username and password.
b
barbsan

I am getting this while cloning app from 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

Click on Your profile and settings Then Create app password choose your name password will generated ,paste that password to terminal


S
Sazzad Hissain Khan

That problem happens sometimes due to wrong password. Please check if you are linked with AD password (Active Directory Password) and you recently changed you AD password but still trying git command with old password or not.

Update old AD password

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

Z
ZaMy

I did:

$git pull origin master

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


This worked for me. I've used fetch instead pull but anyway it doesn't matter. Cool!
Beginning August 13, 2021 this will not supported
Feel free to edit and add what works @ZEHINZ! haven't run into this issue for a while so I am not even sure what the updated command is!
A
Anil Reddy

I have got the success using the following commands.

git config --unset-all credential.helper
git config --global --unset-all credential.helper
git config --system --unset-all credential.helper

Try and let me know if these are working for you.


After this, doing git push origin master in any repo you have should prompt you again for your username (same as before) and password (use the Personal Access Token here).
D
Divyanshu Rawat

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

Quick fix is to set your remote URL to point to ssh not https.

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


P
Pang

Try this:

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

P
Pierre

If you have just enabled 2FA :

Modify hidden config file in ./git hidden folder as follow :

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

but what if the folder did not exist yet? I am unable to do even git clone of a private repo in github
Thank you. I spent more than two hours on this issue. Your answer saved my day
A
Arpan Saini

Run Below command, and after than on every push and pull it will ask you to enter the username and password.

  git config credential.helper ""

https://i.stack.imgur.com/69zOn.png

now when you pull/push you will be asked for git credentials. weather you are running through command prompt or Intellij Git.


G
GreenAsJade

Disabling 2 factor authentication at github worked for me.

I see that there is a deleted answer that says this, with the deletion reason as "does not answer the question". If it works, then I think it answers the question...


This is weird. Same happened with me. I just disabled two-factor authentication and it works now for me. :)
P
Paras saini

You might be getting this error because you have updated your password. So on Terminal first make sure you clear your GitHub credentials from the keychain and then push your changes to your repo, terminal will ask for your username and password.


B
BiAiB

In case you get this error message in this situation:

using github for entreprise

using credential.helper=wincred in git config

using your windows credentials which you changed recently

Then look at this answer: https://stackoverflow.com/a/39608906/521257

Windows stores credentials in a credentials manager, clear it or update it.


A
Ajay Deepak

Control panel Credential manager Look for options webcredentials and windows credentials in either one you will find github credentials fix it with correct credentials open new instance of git bash you should be able to perform your git commands.

This worked for me, I was able to pull and push into my remote repo.


O
Olga Kliushkina

I had the same issue. And I solved it by changing the remote branch's path from https://github.com/YourName/RepoName to git@github.com:YourName/RepoName.git in the repo's settings of the client app.


You are trying to solve the problem using SSH link. I would prefer working with HTTPS and your answer can not help me.
A
Arthur Bowers

I'm constantly running into this problem. Make sure you set git --config user.name "" and not your real name, which I've done a few times..


M
Muhammad Awais

I just disable the Two-factor authentication and try again. It works for me.


S
Sarah Dwyer

Since you probably want to keep 2FA enabled for your account, you can set up a ssh key and that way you won't need to type your Github credentials every time you want to push work to Github.

You can find all the ssh setup steps in the documentation. First, make sure you don't currently have any ssh keys (id_rsa.pub, etc.) with $ ls -al ~/.ssh


G
Grim

There is a issue on Windows using cmd-Greetings

There is a issue on Windows using cmd-Greetings who will not let you clone private repositories. Remove that cmd-greeting described in this documentation (keyword Command Processor):

Known-Issues

I can confirm that other clients like SourceTree, GitKraken, Tower and TortoiseGit affected to this issue too.


L
Lolo

There are many reasons why this might happen. In my case, none of the solutions worked. In particular, git pull origin master did not ask me for my username and password.

I was on Windows with a github password recently changed. I was using the credential manager to manage my password. Here is what worked for me:

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:. In my case, the target name was github..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.


P
Preeti Maurya

one of the best and easiest way

just disabled to two-way of authentication on github go to control panel--> windows credentials--> click on add generic credentials

just manually you have to type add URL of Github: hhtps://www.github.com username: your username password: your password then save to it

3)while using a git push command so, you have to need to generate a token on Github go back to again, on Github > setting> developer setting> generate token

hope this would be helpful....


S
Sandesh Jayaprakash

This solution worked for me:

open Control Panel Go to Credential Manager Click Window Credentials In Generic Credential section ,there would be git url, update username and password Restart Git Bash and try for clone


This answer duplicates an existing answer which is not useful. When you have enough reputation (15, I believe) you can vote up answers that you find useful. Voting would be the correct response rather than adding this duplicate answer.