GitHub: invalid username or password

668,313

Solution 1

https://[email protected]/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://[email protected]:eurydyce/MDANSE.git or just [email protected]:eurydyce/MDANSE.git

git remote set-url origin [email protected]: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"] [email protected]: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.

Solution 2

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://[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:

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

  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

Solution 3

Solution steps:

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

Solution 4

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.

Solution 5

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://[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 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: [email protected]:username/repository. To update your URL use this command:

git remote set-url origin [email protected]:username/repository
Share:
668,313
Eurydice
Author by

Eurydice

Updated on July 08, 2022

Comments

  • Eurydice
    Eurydice almost 2 years

    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://[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

    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?