Using GitHub password in terminal when 2FA is ON

Amit Merchant · May 21, 2020 ·

If you’re using GitHub repository’s web URL as its remote and if you’ve two-factor authentication turned on for your account, you’re going to face an issue in authenticating your account while doing certain git actions such as git push.

For instance, for my project Pomolectron, I’m using its web URL ( as its remote. And now if I want to push something to the repository, I’d be asked to enter my username and password to do so.

But upon entering my GitHub password, I get the following error where it states “remote: Invalid username or password.”.

That is because I’ve two-factor authentication enabled for my account. So, I can not use my GitHub account’s master password alone to authenticate my account.

Authentication using Personal Access Tokens

To authenticate in this kind of scenario, you’ll need to use a Personal Access Token which you can generate from your account’s settings.

  • Give your token a descriptive name.

  • Select the scopes, or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.

  • Click Generate token.

  • Copy the generated token. For security reasons, after you navigate off the page, you will not be able to see the token again.

Now, you can use this Personal Access Token as your password in the terminal by pasting it on the password prompt and you’ll be authenticated successfully!

Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!