Update GitHub authentication to use token on macOS (rather than password)?

16,911

Solution 1

Step 1

Copy this into your terminal to unset existing GitHub login credentials:

git config --global --unset credential.helper
git credential-osxkeychain erase
host=github.com
protocol=https

Step 2

Open a new terminal window, and set the name and email for commits:

git config --global user.name "Your Name"
git config --global user.email [email protected]

Step 3

Run a git push or git clone a private repository so GitHub prompts you to enter your username and password.

For the username, simply enter your email.

For the password paste in your token (i.e. copy the token from GitHub website where you created it and paste it in).

Solution 2

The below command worked for me on mac as mentioned in https://gist.github.com/jonjack/bf295d4170edeb00e96fb158f9b1ba3c.

security delete-internet-password -l github.com

After running this command in terminal, run a git clone command and it will ask you the username and password. On password please provide your access token which you created from the github web portal.

Solution 3

TLDR; your token will be your new password. Storing it in the mac keychain makes it a hassle that you don't have to track. Here's the steps on how to update your password with the token.

I see that you've already created a token, which if reading the deprecation notice you might think that's all you need to do. Here's the instructions on creating a token for anyone that hasn't yet: https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line

But as you've mentioned, the next step is to replace using a password with instead using the token.

@stevec shared correctly how to do this on the terminal, but you may also open the keychain app and do it there.

  1. Use the mac search for "keychain" and open Keychain Access.app
  2. Search for GitHub. You may see two options: an application password and an internet password
  3. Open the application password. You may check the box for "Show password and likely see that this still uses your password rather than the token.

Replace that password with your token. That worked for me.

Share:
16,911

Related videos on Youtube

stevec
Author by

stevec

Updated on September 16, 2022

Comments

  • stevec
    stevec over 1 year

    After creating a token, how do you unset the existing password and use the token instead?

    I tried running osxkeychain command git config --global credential.helper osxkeychain but it doesn't change anything. I also tried unsetting the user password with git config --global --unset user.password, and I tried opening Keychain Access application and delete GitHub entries, but neither worked.

  • bomben
    bomben about 2 years
    I am running old High Sierra and it hangs at git credential-osxkeychain erase.
  • stevec
    stevec about 2 years
    @bomben try hitting enter twice.
  • stevec
    stevec about 2 years
    @bomben I just read this and I think you need to copy all 4 lines in the first code section of my answer, then hit enter twice and it should work :)
  • bomben
    bomben about 2 years
    Thanks for the fast reply. However, I used PyCharm now to set things up. stackoverflow.com/questions/22348093/…