Skip to content

GitHub Password Authentication Removal: Using Personal Access Tokens and SSH

IMPORTANT UPDATE

As of August 13, 2021, GitHub removed password authentication for Git operations. You must now use personal access tokens or SSH keys to interact with your repositories.

Problem Statement

When attempting to perform Git operations like git push, git pull, or git clone, you may encounter the error:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for...

This occurs because GitHub no longer accepts account passwords for Git operations, requiring alternative authentication methods.

Option 1: Use Personal Access Tokens (PAT)

Personal Access Tokens provide a secure alternative to password authentication for HTTPS Git operations.

Generating a PAT

  1. Go to GitHub Settings → Developer Settings → Personal Access Tokens → Tokens (classic)
  2. Click Generate new token (classic)
  3. Provide a descriptive note for the token
  4. Set an appropriate expiration date
  5. Select necessary scopes (typically repo for full repository access)
  6. Click Generate token
  7. Copy the token immediately - you won't be able to see it again

Configuring Your System with PAT

bash
# Clone with token
git clone https://<TOKEN>@github.com/<USERNAME>/<REPO>.git

# Or update existing remote URL
git remote set-url origin https://<TOKEN>@github.com/<USERNAME>/<REPO>.git
bash
# Same commands work on Windows
git remote set-url origin https://<TOKEN>@github.com/<USERNAME>/<REPO>.git

Storing PAT in System Credential Manager

bash
# Use Keychain Access to store token
# Search for "Keychain Access" → Find "github.com" → Update password with token
bash
# Use Credential Manager
# Control Panel → User Accounts → Credential Manager → Windows Credentials
# Find "git:https://github.com" → Edit → Replace password with token
bash
# Cache credentials temporarily
git config --global credential.helper cache

# Or store permanently (use with caution)
git config --global credential.helper store

SSH keys provide a more secure and convenient authentication method that doesn't require token management.

Setting Up SSH Keys

  1. Generate SSH key pair (if you don't have one):

    bash
    ssh-keygen -t ed25519 -C "your_email@example.com"
  2. Add SSH key to SSH agent:

    bash
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
  3. Add public key to GitHub:

  4. Update remote URL to use SSH:

    bash
    git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
  5. Test SSH connection:

    bash
    ssh -T git@github.com

Option 3: Use GitHub CLI

The GitHub CLI tool simplifies authentication and Git operations:

bash
# Install GitHub CLI (macOS with Homebrew)
brew install gh

# Authenticate with GitHub
gh auth login

# Setup Git to use GitHub CLI authentication
gh auth setup-git

IDE-Specific Solutions

JetBrains IDEs (IntelliJ, WebStorm, PyCharm, etc.)

  1. Open Settings/PreferencesVersion ControlGitHub
  2. Click Add Account
  3. Select Log In with Token
  4. Paste your personal access token
  5. Click Add Account

Android Studio

  1. Generate a personal access token on GitHub
  2. Remove existing GitHub account from Android Studio
  3. Add account again using the new token
  4. If issues persist, update the remote URL in terminal:
    bash
    git remote set-url origin https://<TOKEN>@github.com/<USERNAME>/<REPO>.git

Sourcetree

  1. Go to ToolsOptionsAuthentication
  2. Select your GitHub account
  3. Click Refresh OAuth Token
  4. Or update repository URL to include token:
    bash
    https://<TOKEN>@github.com/USERNAME/REPOSITORY.git

Advanced Configuration

Centralized PAT Management

For users with multiple repositories, manage tokens centrally using Git's include functionality:

In each repository's .git/config:

git
[remote "origin"]
    url = https://github.com/<user>/<repo>.git

[include]
    path = ~/.github-token

In ~/.github-token:

git
[url "https://<TOKEN>@github.com/<user>/"]
    pushInsteadOf = https://github.com/<user>/

Force SSH for All Operations

To always use SSH instead of HTTPS:

bash
git config --global url."git@github.com:".insteadOf "https://github.com/"

Troubleshooting Common Issues

"No such remote 'origin'"

If you encounter this error when trying to set URL:

bash
# First add the remote origin
git remote add origin https://github.com/USERNAME/REPOSITORY.git

# Then update the URL with token
git remote set-url origin https://<TOKEN>@github.com/USERNAME/REPOSITORY.git

Token Still Not Working

  1. Ensure token has appropriate permissions (repo scope)
  2. Check token expiration date
  3. Verify there are no typos in the token
  4. Clear cached credentials:
    bash
    git config --global --unset credential.helper
    git credential-cache exit

Organization Repository Access

For organization repositories, ensure:

  1. Your account has access to the organization
  2. The token has appropriate organization permissions
  3. You're signed in to the organization with your token

Best Practices

  1. Use SSH when possible - More secure and doesn't require token management
  2. Set appropriate token expiration - Balance security and convenience
  3. Use token with least privileges - Only grant necessary scopes
  4. Store tokens securely - Use system credential managers rather than hardcoding
  5. Rotate tokens regularly - Especially if compromised or team members leave

Conclusion

The transition away from password authentication to PATs or SSH keys enhances security for GitHub operations. While initially requiring setup, these methods provide more controlled and secure access to your repositories. For most users, SSH keys offer the best combination of security and convenience, while PATs provide flexibility for automated systems and CI/CD pipelines.

QUICK FIX

For immediate resolution, update your remote URL:

bash
git remote set-url origin https://<TOKEN>@github.com/USERNAME/REPOSITORY.git

Or switch to SSH:

bash
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

For additional help, refer to GitHub's official documentation on authentication methods.