It's a fairly common complaint that after enabling github two factor authentication that command line utilities
stop working. The underlying issue is command line utilities send your username and password with each request
to github, using two factor authentication disables github from accepting just your username and password, so your
command line utilities such as git
appear to stop working. Github will still accept a personal access token instead
of your password however.
You'll need to store your personal access token in your netrc as two factor authentication prevents your username/password from being used on the command line. To fix this follow these steps:
- Go to https://github.com/settings/tokens/new
- Put in the name "Command Line" for the Token Description
- For the scopes, enable all the top scopes (e.g., click the checkboxes: repo, admin:org, etc, etc...), then click
Generate Token
- You'll need to copy the token it generates, it's in a green window with a clipboard icon next to it.
- Open a terminal window (Go to the Applications folder, Utilities folder, run Terminal application)
touch ~/.netrc; open -a "TextEdit" ~/.netrc
(or the CLI editor of your choice)- Enter:
machine github.com
login [your_github_login_name]
password [the_token_copied_from_above]
machine api.github.com
login [your_github_login_name]
password [the_token_copied_from_above]
Make sure to replace [your_github_login_name] with your github login, NOT your email address. Make sure to replace [the_token_copied_from_above] with the token.
- Save these changes, and close the editor.
- Run
chmod 600 ~/.netrc
in the terminal - To test this run
curl -n https://api.github.com/user
, you should see your user information in a JSON response. You can also test this by trying to clone out a private https repo, it should no longer ask for your password.
- Install git system wide, (see https://git-scm.com/download/win)
- Install Microsoft Github/Git Credential Manager (see https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/tag/v1.12.0)
- If you're using SourceTree or another software that uses github, make sure its set to use the system wide git and not its embedded one.
- Use things as normal, when prompted you'll be asked for your username and password; you may also be asked for your two factor auth token when logging in (it'll auto magically appear as a pop up when needed).
Worked for me, thank you very much!