As outlined here, there are a couple of situations where you need to authenticate with GitHub by using an Acces Token:-
- If you have Two-Factor Authentication (2FA) enabled.
- You are accessing an organisations protected content using SAML Single-Sign On (SSO).
In your GitHub account, go to Settings / Developer settings / Personal access tokens
and select Generate New Token
. Make a note of the token somewhere safe since this is the only chance you get to see it.
When you now need to authenticate with GitHub on the command line you will need to use the token instead of your password (even though git will ask for your Github password).
git clone https://github.com/username/repo.git
Username: your_username
Password: your_token
Using the token on your Mac the first time should automatically add it to your OSX Key Chain so that you do not need to enter it every time you are using the Github API. If you check your local git configuration you should see that there is a credential.helper
key pointing to the OSX Key Chain.
git config -l
credential.helper=osxkeychain
[email protected]
user.name=Joe Bloggs
If you need to regenerate the Access Token (maybe you got a new Mac and didn't make a note of your existing token) then follow the procedure before in your Github account settings to generate a new token.
Then, on your local Mac you can either use the Keychain Access app to delete the old token (search for Github.com in the App), or, use the following command.
git credential-osxkeychain erase
Now, the next time you do a clone/pull/push
etc Github should prompt you for your new token on the command line and entering the new token should also add it to youe local Key Chain.