GitHub Error: Authentication Failed from the Command Line

After setting up 2 Factor Authentication on GitHub, I couldn’t push my remote repositories from the command line anymore.

When I tried to push a remote repo, the command line threw this error:

~ :> git push origin my-branch
Username for '': myusernamePassword for '': mypasswordremote: Invalid username or password.fatal: Authentication failed for '

The error stumped me — and made me vow that, when I did ultimately get to the bottom of it, I’d do my best to pay the knowledge forward.

How to Authenticate on GitHub with 2FA

Command line authentication requires a personal access token.

Go to Settings:

Then Developer Settings:

Then Personal access tokens >> Tokens (classic):

Generate a new Personal Access Token (also classic). Make sure you copy the Personal Access Token as soon as it gets generated — you won’t be able to see it again!

Paste the Personal Access Token into the “Password” field when you authenticate via the command line.

GitHub has published official instructions for this flow here (though without glam screenshots…)

Hope this helps — happy coding!



Tech Fellow @AspenPolicyHub & #MovingForward Executive Director. Ex- @UberEngineering .

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ginny Fahs

Tech Fellow @AspenPolicyHub & #MovingForward Executive Director. Ex- @UberEngineering .