Forked from jonjack/add-update-refresh-github-access-token-on-mac.md
Created
November 24, 2022 01:54
-
-
Save ashish-ad/43f80e1093b54d3dc5fa34e2d534390d to your computer and use it in GitHub Desktop.
Revisions
-
jonjack revised this gist
Oct 19, 2022 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,8 +50,6 @@ You should now be prompted for your Github credentials when attempting a `git pu ## Troubleshooting ```sh $ git pull -
jonjack revised this gist
Oct 19, 2022 . 1 changed file with 5 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,16 +35,13 @@ If your existing token has expired, or been revoked, or you are on a new machine ### Remove an existing token from your Mac keychain You can remove an existing password or token stored in the `osxkeychain` using the following command. ```bash $ git credential-osxkeychain erase ↵ host=github.com ↵ protocol=https ↵ ↵ ``` You should now be prompted for your Github credentials when attempting a `git pull/clone/push` etc and your token should automatically get stored in the `osxkeychain`. If subsequent calls to Github repeatedly prompt you for your credentials then likely the `credential.helper` is not set - see next section. -
jonjack revised this gist
Jan 18, 2022 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,15 @@ Follow the instructions on Github to [Create an Access Token in Github](https:// By default, git credentials are not cached so you need to tell Git if you want to avoid having to provide them each time Github requires you to authenticate. On Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. You can tell Git you want to store credentials in the osxkeychain by running the following:- ```sh git config --global credential.helper osxkeychain ``` ### Add your access token to the osxkeychain Now issue a command to interract with Github which requires authentication, eg. `git clone` or `git pull`. When you are prompted to supply your _Password for 'https://[email protected]':_ you enter your access token instead. Your token should now get cached in the osxkeychain automatically. ```sh $ git clone https://github.com/username/repo.git -
jonjack revised this gist
Jan 17, 2022 . 1 changed file with 45 additions and 50 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,91 +1,86 @@ ## Using an Access Token for the first time Follow the instructions on Github to [Create an Access Token in Github](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) ### Configure Git to use the osxkeychain By default, git credentials are not cached so you need to tell Git if you want to avoid having to provide them each time Github requires you to authenticate. On Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. ```sh git config --global credential.helper osxkeychain ``` ### Add your access token to the osxkeychain To add your new github access token to the keychain you just need to issue a command whto interract with Github which requires you to authenticate yourself, eg. `git clone` or `git pull`. When you are prompted to supply your _Password for 'https://[email protected]':_ you enter your access token instead. ```sh $ git clone https://github.com/username/repo.git Cloning into 'repo'... Username for 'https://github.com': your_github_username Password for 'https://[email protected]': your_access_token ``` --- ## Updating an existing Access Token ### Regenerate token on Github If your existing token has expired, or been revoked, or you are on a new machine and do not have access to the existing token then you can regerate a new one in the Github console `Settings` -> `Developer settings` -> `Personal access tokens`. ### Remove an existing token from your Mac keychain You can check if you have an existing password or token stored in the `osxkeychain` using the following command. ```bash $ security find-internet-password -l github.com ``` If this returns a result you can then delete it using the following. ```bash $ security delete-internet-password -l github.com ``` You should now be prompted for your Github credentials when attempting a `git pull/clone/push` etc and your token should automatically get stored in the `osxkeychain`. If subsequent calls to Github repeatedly prompt you for your credentials then likely the `credential.helper` is not set - see next section. --- ## Troubleshooting If no entry for Github was found in the key chain (`security find-internet-password -l github.com`) then see if you can interract with Github by doing something like a `git clone` or `git pull`. ```sh $ git pull remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/user/repo.git/' ``` If authentication fails and you are not prompted to enter your credentials, like in the above example, or you are repeatedly challenged by Github for your credentials, then check if you have the `credential.helper` set. ```sh git config --global credential.helper ``` If not, or it is set to something other than `osxkeychain`, then update/set it. ```sh git config --global --unset credential.helper git config --global credential.helper osxkeychain ``` Then try again and you should now be prompted for your credentials. ```sh $ git clone https://github.com/username/repo.git Cloning into 'repo'... Username for 'https://github.com': your_github_username Password for 'https://[email protected]': your_access_token ``` Ensure you provide your access token rather than password when prompted. -
jonjack revised this gist
Dec 21, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,7 +64,7 @@ Or else if it does not exist then you should see something like this. 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 -
jonjack revised this gist
Dec 21, 2021 . 2 changed files with 91 additions and 111 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,111 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ ## 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://[email protected]':_ 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://[email protected]': 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 [email protected] 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 <blob>="github.com" 0x00000008 <blob>=<NULL> "acct"<blob>="joebloggs" "atyp"<blob>="dflt" "cdat"<timedate>=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 <blob>="github.com" 0x00000008 <blob>=<NULL> "acct"<blob>="joebloggs" "atyp"<blob>="dflt" "cdat"<timedate>=0x32303230303932383233343630395A00 "20200928234609Z\000" "crtr"<uint32>="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_. -
jonjack revised this gist
Sep 9, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,8 @@ user.name=Joe Bloggs ## Updating to a new Access Token > April 2021 Notice on possible future updates on token length -> [Authentication token format updates are generally available](https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available/). If you need to regenerate the Access Token then log into your Github dashboard 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`. -
jonjack revised this gist
Sep 9, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,7 +70,7 @@ attributes: password has been deleted. ``` Now, the next time you attempt a `clone/pull/push` etc on a private repo, the Github API should prompt you for your Username/Password. Note that you enter your new token when prompted for _Password_. ```bash Username for 'https://github.com': your_github_username -
jonjack revised this gist
Sep 9, 2021 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,7 +70,14 @@ attributes: password has been deleted. ``` Now, the next time you attempt a `clone/pull/push` etc on a private repo, the Github API should prompt you for your Username/Password. Note that you enter your new token when prompted for _Paswword_. ```bash Username for 'https://github.com': your_github_username Password for 'https://[email protected]': your_access_token ``` The new token should get added to your local Key Chain so you should not need to specify it again until the next time you decide/need to regenerate a new one. ### To check if your access token exists in your keychain -
jonjack revised this gist
Sep 9, 2021 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,17 +39,23 @@ If you need to regenerate the Access Token then log into your Github dashboard a ### Remove existing token from your Keychain The general approach described in the Github documentation is to use the following git command to erase your local credentials. #### Note, it is worth reading the rest of this section before running the following command. ```bash $ git credential-osxkeychain erase ``` The above would appear to be increasingly ineffective and, as many report in the comments below, often just hangs. An alternative approach to deleting the existing token is to try the following command. ```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" -
jonjack revised this gist
Jun 30, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ [email protected] user.name=Joe Bloggs ``` ## Updating to a new Access Token > April 2021 - notice on possible future updates on token length [Authentication token format updates are generally available](https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available/). -
jonjack revised this gist
Jun 30, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -85,7 +85,7 @@ attributes: 0x00000008 <blob>=<NULL> "acct"<blob>="joebloggs" "atyp"<blob>="dflt" "cdat"<timedate>=0x32303730303933373333343635395A00 "20200938235909Z\000" ...(truncated) ``` -
jonjack revised this gist
Jun 30, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ user.name=Joe Bloggs If you need to regenerate the Access Token then log into your Github dashboard 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 Keychain The general approach described in the Github documentation is to use the following git command to erase your local credentials. __Note, it is worth reading the rest of this section before running this.__ @@ -66,7 +66,7 @@ password has been deleted. Now, the next time you attempt a `clone/pull/push` etc on a private repo, the Github API should prompt you for your new token on the command line and entering the new token should also add it to your local Key Chain which you can check as below. ### To check if your access token exists in your keychain To check if the token still exists you can try this. -
jonjack revised this gist
Jun 30, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ As outlined [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/), there are a couple of situations where you may want/need to authenticate with GitHub by using an Access Token:- 1. If you have Two-Factor Authentication (2FA) enabled. 2. You are accessing an organisations protected content using SAML Single-Sign On (SSO). ## Using an Access Token for the first time ### 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 clone a private repository on the command line Github should challenge you for your credentials. Even though it will prompt you for your _Password for 'https://[email protected]':_ this is actually where you should supply your new access token. -
jonjack revised this gist
Jun 30, 2021 . 1 changed file with 67 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,30 @@ As outlined [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/), there are a couple of situations where you need to authenticate with GitHub by using an Access Token:- 1. If you have Two-Factor Authentication (2FA) enabled. 2. You are accessing an organisations protected content using SAML Single-Sign On (SSO). ## Using an Access Token for the first time #### 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 clone a private repository on the command line Github should challenge you for your credentials. Even though it will prompt you for your _Password for 'https://[email protected]':_ this is actually where you should supply your new access token. ```bash $ git clone https://github.com/username/repo.git Cloning into 'repo'... Username for 'https://github.com': your_github_username Password for 'https://[email protected]': 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 [email protected] @@ -29,15 +33,65 @@ user.name=Joe Bloggs ## Updating the Access Token > April 2021 - notice on possible future updates on token length [Authentication token format updates are generally available](https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available/). If you need to regenerate the Access Token then log into your Github dashboard 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 Keychain The general approach described in the Github documentation is to use the following git command to erase your local credentials. __Note, it is worth reading the rest of this section before running this.__ ```bash $ git credential-osxkeychain erase ``` The above would appear to be increasingly ineffective and, as many report in the comments below, often just hangs. An alternative approach to delete is to try the following. ```bash $ security delete-internet-password -l github.com keychain: "/Users/jblogs/Library/Keychains/login.keychain-db" version: 512 class: "inet" attributes: 0x00000007 <blob>="github.com" 0x00000008 <blob>=<NULL> "acct"<blob>="joebloggs" "atyp"<blob>="dflt" "cdat"<timedate>=0x32303230303932383233343630395A00 "20200928234609Z\000" "crtr"<uint32>="aapl" ... (truncated) password has been deleted. ``` Now, the next time you attempt a `clone/pull/push` etc on a private repo, the Github API should prompt you for your new token on the command line and entering the new token should also add it to your local Key Chain which you can check as below. #### To check if your access token exists in your keychain To check if the token still exists you can try this. ```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 <blob>="github.com" 0x00000008 <blob>=<NULL> "acct"<blob>="joebloggs" "atyp"<blob>="dflt" "cdat"<timedate>=0x32303230303932383233343630395A00 "20200928234609Z\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. ``` -
jonjack revised this gist
Sep 8, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ user.name=Joe Bloggs ## Updating the Access Token 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. -
jonjack revised this gist
Sep 8, 2018 . 1 changed file with 31 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,5 +9,35 @@ In your GitHub account, go to `Settings / Developer settings / Personal access t ### Add the token to your local OSX Key Chain 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_). ```bash 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. ```bash git config -l credential.helper=osxkeychain [email protected] user.name=Joe Bloggs ``` ## Updating the Access Token If you need to regenerate the Access Token then follow the procedure before in your Github account settings. 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. ```bash 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. -
jonjack revised this gist
Sep 8, 2018 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,13 @@ As outlined [here](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/), there are a couple of situations where you need to authenticate with GitHub by using an Acces Token:- 1. If you have Two-Factor Authentication (2FA) enabled. 2. You are accessing an organisations protected content using SAML Single-Sign On (SSO). ### 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 local OSX Key Chain When you -
jonjack created this gist
Sep 8, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ If you have Two-Factor Authentication (2FA) enabled on GitHub, or are accessing an organisations protected content using SAML Single-Sign On (SSO), then you will need to authenticate using an Access Token.