Monday, February 28, 2022

Github authenticating with Personal Access Token


Creating a token

Verify your email address, if it hasn't been verified yet.


In the upper-right corner of any page, click your profile photo, then click Settings.

In the left sidebar, click  Developer settings.


In the left sidebar, click Personal access tokens.

Click Generate new token.

Give your token a descriptive name.

To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.

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.

To use your token to authenticate to an organization that uses SAML single sign-on, authorize the token. For more information, see "Authorizing a personal access token for use with SAML single sign-on" in the GitHub Enterprise Cloud documentation.


Using a token on the command line

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.


For example, on the command line you would enter the following:


$ git clone https://github.com/username/repo.git

Username: your_username

Password: your_token

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.


If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.


Instead of manually entering your PAT for every HTTPS Git operation, you can cache your PAT with a Git client. Git will temporarily store your credentials in memory until an expiry interval has passed. You can also store the token in a plain text file that Git can read before every request. For more information, see "Caching your GitHub credentials in Git."

references:

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

No comments:

Post a Comment