## Using an Access Token for the first time Alternative read -> [Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) ### Create an Access Token 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. ### Add the token to your OSX Key Chain When you next interract with a private repository on the command line Github should challenge you for your credentials. When you are prompted to supply your _Password for 'https://username@github.com':_ you enter your access token instead. ```bash $ git clone https://github.com/username/repo.git Cloning into 'repo'... Username for 'https://github.com': your_github_username Password for 'https://username@github.com': your_access_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 interracting with 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. ```bash $ git config -l credential.helper=osxkeychain user.email=joe.bloggs@gmail.com user.name=Joe Bloggs ``` ## Updating an existing Access Token ### Regenerate token on Github If you need to regenerate or [revoke](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/token-expiration-and-revocation) an existing Access Token then log into your [Github](https://github.com/) account and navigate to `Settings` -> `Developer settings` -> `Personal access tokens` and choose to either `Generate new token`, or replace your existing token either by choosing `Delete` and `Generate new token`, or viewing your current token and choosing `Regenerate token`. ### Remove existing token from your Mac keychain You can check if you have an existing token using the following command. ```bash $ security find-internet-password -l github.com ``` Which should report something like this if it exists. ```bash keychain: "/Users/jbloggs/Library/Keychains/login.keychain-db" version: 512 class: "inet" attributes: 0x00000007 ="github.com" 0x00000008 = "acct"="joebloggs" "atyp"="dflt" "cdat"=0x32303730303933373333343635395A00 "20200938235909Z\000" ...(truncated) ``` Or else if it does not exist then you should see something like this. ```bash security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain. ``` To erase an existing access token use. ```bash $ security delete-internet-password -l github.com ``` If you had a token previously stored then running the above should output something like the following. ```bash keychain: "/Users/jblogs/Library/Keychains/login.keychain-db" version: 512 class: "inet" attributes: 0x00000007 ="github.com" 0x00000008 = "acct"="joebloggs" "atyp"="dflt" "cdat"=0x32303230303932383233343630395A00 "20200928234609Z\000" "crtr"="aapl" ... (truncated) password has been deleted. ``` Now, the next time you attempt a `clone/pull/push` etc on a private repo Github should prompt you for your Username/Password. Note that you enter your new token when prompted for _Password_.