Git authentication fails after enabling 2FA
You need to generate an access token. You can create one by going to your settings page.
Use this access token as your password in the command line.
An end-to-end solution takes 3 steps.
Kudos to Gergo Erdosi. His answer is largely right, it is just that Github changes that setting page. As of late 2016, you need to generate an access token from your Personal access tokens page.
Use this access token as your password in the command line.
You can persist your user name by including it into your project remote url. One of the way to do it is to edit your
.git/config
to modify theurl
line into the following format:url = https://[email protected]/owner/repo.git
You can persist your password by run this for one time only:
$ git config credential.helper store
and then your future git password(s) will be stored in ~/.git-credentials, in plaintext, using the format
https://user:[email protected]
.Storing password(s) in plaintext would normally be considered as a security risk. But in this 2FA case, the credential is NOT your real password, it is a randomly generated string. So it is as secure as using
a ssh private keya passphrase-less ssh private key. CAVEAT: keep in mind that, if you happen to also use another git account(s) without 2FA on this machine, those real password(s) will also be stored in plaintext.
PS: Alternatively, you could choose to use ssh-based login, using a passphrase-protected ssh private key, which would be more secure and less convenient, but it is outside the scope of this answer.