GitHub Error: Authentication Failed from the Command Line

Ginny Fahs
Apr 16, 2018 · 2 min read

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 'https://github.com': myusernamePassword for 'https://myusername@github.com': mypasswordremote: Invalid username or password.fatal: Authentication failed for 'https://github.com/my-repository

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:

Image for post
Image for post

Then Developer Settings:

Image for post
Image for post

Then Personal access tokens:

Image for post
Image for post

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

Image for post
Image for post

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

Image for post
Image for post

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

Hope this helps — happy coding!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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