GitHub Personal Access Token - Quick Setup
GitHub Personal Access Token - Quick Setup
If you prefer not to set up SSH keys, you can use Personal Access Tokens (PAT) for HTTPS authentication with GitHub.
Why Use Personal Access Tokens?
Since August 2021, GitHub no longer accepts passwords for Git operations. Your options are:
- SSH Keys (recommended for professionals)
- Personal Access Tokens (easier setup, good for beginners)
Step 1: Create Your Token
Navigate to Token Settings
- Go to GitHub.com and sign in
- Click your profile picture (top right corner)
- Click Settings
- Scroll down to Developer settings (left sidebar)
- Click Personal access tokens
- Click Tokens (classic)
Quick link: https://github.com/settings/personal-access-tokens/new
Generate New Token
- Click Generate new token (classic)
- Enter your GitHub password if prompted
Configure Your Token
- Note: Give it a descriptive name (e.g., “Git Command Line Access”)
- Expiration: Choose 30 days, 90 days, or custom (never use “No expiration” for security)
- Scopes: Check the
repobox for full repository access
Save Your Token
- Click Generate token
- IMMEDIATELY COPY THE TOKEN - you won’t see it again!
- Save it somewhere secure (password manager, secure note, etc.)
Step 2: Use Your Token
For Git Operations
When Git prompts for credentials:
Username: your-github-username
Password: ghp_your-personal-access-token-here
Important: Use the token as your password, not your actual GitHub password!
Example: Clone a Repository
git clone https://github.com/username/repository.git
# When prompted:
# Username: username
# Password: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Example: Push Changes
git push origin main
# When prompted:
# Username: username
# Password: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Token Management
Store Credentials (Optional)
To avoid entering the token every time:
Windows:
git config --global credential.helper manager-core
macOS:
git config --global credential.helper osxkeychain
Linux:
git config --global credential.helper store
After running this, Git will remember your token after the first use.
Token Security Best Practices
- Treat tokens like passwords - never share them
- Set expiration dates - rotate tokens regularly
- Use minimal scopes - only grant necessary permissions
- Store securely - use a password manager
- Revoke unused tokens - clean up old tokens regularly
Regenerate Expired Tokens
- Go back to GitHub Settings → Developer settings → Personal access tokens
- Click on your expired token
- Click Regenerate token
- Update your stored credentials with the new token
Troubleshooting
“Authentication failed” Error
- Double-check you’re using the token, not your GitHub password
- Verify the token hasn’t expired
- Ensure the token has the correct scopes (check
repo)
Token Not Working
- Make sure you copied the entire token (starts with
ghp_) - Check if your organization requires SSO authorization for tokens
- Verify the token hasn’t been revoked
Clear Stored Credentials
If you need to update stored credentials:
Windows:
- Open “Credential Manager” → “Windows Credentials”
- Find and delete GitHub entries
macOS:
- Open “Keychain Access”
- Search for “github” and delete entries
Linux - WSL:
- Delete
~/.git-credentialsfile
When to Use SSH Instead
Consider switching to SSH keys if you:
- Use Git frequently (multiple times per day)
- Work on multiple machines
- Want more security
- Are in a professional development environment
- Find token management annoying
SSH is more complex to set up but more convenient long-term.
Quick Reference:
- Token URL: https://github.com/settings/personal-access-tokens/new
- Scope needed:
repo - Use token as password when prompted
- Tokens start with
ghp_