GitHub: invalid username or password
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
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.
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
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.