Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Support for password authentication was removed: HTTPS push to GitHub

Password auth for Git over HTTPS ended in 2021. Clear the cached credential, use a token with the right scopes, and authorize it for SSO.

~5 min readGit
#Git#GitHub#Authentication#CI
A git push crate refused at a cyan authentication gate, amber password plate crossed out and token key

Introduction & Quick Summary

text
remote: Support for password authentication was removed on August 13, 2021. fatal: Authentication failed for 'https://github.com/owner/repo.git/'

GitHub stopped accepting an account password for Git over HTTPS. The credential is now a personal access token, a fine-grained token, an SSH key, or a GitHub App installation token, and the error appears whenever the stored credential is still a password.

Why it keeps happening after the first fix:

  • A cached password is still in the credential store. Windows Credential Manager, macOS Keychain, and ~/.git-credentials each keep the old entry and hand it back before the remote is even contacted.
  • The token is expired or has no repository access. Fine-grained tokens expire, and they need Contents permission on the specific repositories.
  • Organization SSO is not authorized. A valid token is rejected for an org repository until the token is approved for that organization.
  • CI has no terminal to prompt on. GIT_TERMINAL_PROMPT=0 or a non-interactive runner turns the same auth failure into could not read Username.
MessageMeaningFix
Support for password authentication was removedA password was sentReplace the stored credential with a token
fatal: Authentication failed for ...Credential rejectedCheck expiry, scopes, and SSO
could not read Username for 'https://github.com'No terminal, no credentialProvide a token in the environment
remote: Permission to owner/repo.git denied to userAuthenticated but not authorizedGrant repo access or re-scope the token
fatal: could not read from remote repositoryAny of the aboveRead the line above it

Core Mechanics, Signatures & Reproducible Setup

HTTPS Git uses HTTP Basic authentication with a username and a secret. git asks a credential helper for host=github.com, and if the helper has nothing it prompts. Since 2021 the secret must be a token, and the token is what the Authorization header carries, base64-encoded.

A reproduction is a clone with a deliberately wrong secret:

bash
cd /tmp && rm -rf demo GIT_TERMINAL_PROMPT=0 git clone https://github.com/octocat/Hello-World.git demo # fatal: could not read Username for 'https://github.com': terminal prompts disabled
bash
# the same request with a token, without writing it into shell history read -rs GH_TOKEN git clone "https://x-access-token:${GH_TOKEN}@github.com/owner/private-repo.git" demo unset GH_TOKEN

The working setup is almost always a credential helper plus a token created once:

bash
gh auth login --hostname github.com --git-protocol https --web gh auth setup-git git config --global --get-all credential.helper

gh auth setup-git registers gh as the credential helper for github.com, so git push gets a token from the same login the CLI uses.

Key Comparison Table

The four credential types differ in scope, lifetime, and where they are accepted.

MethodSecretScope controlExpiryWorks for CI
Classic PATghp_...Checkbox scopes (repo, workflow)OptionalYes
Fine-grained PATgithub_pat_...Per-repository, per-permissionRequired, max 1 yearYes
SSH keyPrivate key filePer-key, deploy keys per repoOptionalYes
GitHub App tokenghs_...Installation repositories1 hourYes
Account passwordn/an/an/aNo, rejected

Credential helpers decide where the secret lives and which one wins when several are configured.

HelperPlatformStorageNotes
managerWindows, macOS, LinuxOS credential storeInstalled with Git for Windows
osxkeychainmacOSKeychainDefault with Apple Git
libsecretLinuxSecret ServiceNeeds a running keyring
storeAnyPlain file ~/.git-credentialsReadable by any process
cacheAnyMemory, timeout--timeout=3600
ghAnygh auth tokenSet by gh auth setup-git

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

Clear the stale credential first

A helper that already holds a password keeps returning it, so a new token changes nothing until the old entry is gone.

bash
# macOS printf "protocol=https\nhost=github.com\n\n" | git credential-osxkeychain erase # Windows cmdkey /list | grep github cmdkey /delete:git:https://github.com # Linux with libsecret printf "protocol=https\nhost=github.com\n\n" | git credential-libsecret erase # any platform, plain file helper grep -n github ~/.git-credentials
bash
# confirm which helper answered GIT_TRACE=1 GIT_CURL_VERBOSE=0 git ls-remote https://github.com/owner/repo.git 2>&1 | grep -i credential

After the erase, the next git push prompts once and stores the token under the same host.

Scope and expiry for fine-grained tokens

A fine-grained token that can read the repository but not write produces an authentication failure on push while clone works, which looks like a Git problem rather than a permission one.

text
Repository access: Only select repositories → owner/repo Permissions: Contents → Read and write Metadata → Read-only (mandatory)
# verify what the token can do before debugging git curl -s -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/owner/repo \ | jq '{full_name, permissions}'

A 403 with Resource not accessible by personal access token means the permission is missing, not the credential.

Organization SSO authorization

An organization with SAML SSO rejects tokens that have not been authorized for it. The failure is a 403 on the first fetch, and the fix is one click in the token settings, not a new token.

bash
git ls-remote https://github.com/org/repo.git # remote: The `org` organization has enabled or enforced SAML SSO. # remote: You must use a personal access token with the `read:org` scope...
# check SSO state through the API curl -s -H "Authorization: Bearer $GH_TOKEN" \ https://api.github.com/orgs/org/credential-authorizations | jq '.[] | {login, credential_type, authorized}'

Classic tokens need the read:org scope for the check; fine-grained tokens need the organization to approve the token.

Non-interactive CI without leaking the token

On a runner there is no terminal, so the failure is could not read Username. Two patterns avoid it: a credential helper configured in the job, or an askpass script.

bash
# option 1: gh as the helper gh auth setup-git git push origin HEAD # option 2: askpass, no token in the remote URL export GIT_ASKPASS="$PWD/askpass.sh" export GH_TOKEN="$(cat "$TOKEN_FILE")"
bash
#!/usr/bin/env bash # askpass.sh case "$1" in *Username*) echo "x-access-token" ;; *Password*) echo "$GH_TOKEN" ;; esac

Keeping the token out of the remote URL matters because git remote -v and git config --list are both logged by CI systems.

Switching to SSH to remove the credential entirely

SSH keys avoid token rotation and are accepted for Git over git@github.com: URLs. The trade-off is key management and an agent that must be available.

bash
ssh-keygen -t ed25519 -C "laptop" -f ~/.ssh/id_ed25519_gh eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519_gh gh ssh-key add ~/.ssh/id_ed25519_gh.pub --title "laptop"
bash
git remote set-url origin git@github.com:owner/repo.git ssh -T git@github.com # Hi owner! You've successfully authenticated, but GitHub does not provide shell access.
text
# ~/.ssh/config Host github.com HostName github.com User git IdentityFile ~/.ssh/id_ed25519_gh IdentitiesOnly yes

IdentitiesOnly yes stops the agent from offering other keys first, which is the usual reason an SSH push fails with Permission denied (publickey) despite a working key.

Rewrite a remote that still embeds a token

A remote URL with an embedded token keeps working until the token expires, then fails in a way that looks unrelated. Remove the token from the URL and let the helper supply it.

bash
git remote -v # origin https://ghp_oldtoken@github.com/owner/repo.git (fetch) git remote set-url origin https://github.com/owner/repo.git gh auth setup-git git fetch origin

If the token was committed to a script or workflow, rotate it rather than deleting the line; the secret is already in the history.

Common Compilation/Runtime Mistakes & Version Gotchas

Creating the token with no repo scope. Classic tokens without repo can read public repositories and nothing else. Fine-grained tokens need Contents explicitly, and Metadata is automatic.

Storing the token in the remote URL. It works until rotation, leaks through git remote -v and CI logs, and leaves the credential in every clone's config.

Using store on a shared machine. ~/.git-credentials is plaintext and readable by other local users; cache or an OS keyring is the correct choice.

Expecting a password to work for apps with 2FA. Two-factor authentication is not the issue: even with 2FA disabled, the password is refused for Git operations.

Ignoring the line above the fatal error. fatal: could not read from remote repository is a summary. The remote: line above it names the actual reason, SSO, scope, or a missing repository.

Version notes. Password authentication was removed on 2021-08-13. Fine-grained tokens became generally available in 2022 and require an expiry. gh auth setup-git exists since gh 2.0 and writes credential.https://github.com.helper entries, which take precedence over the global helper. Git 2.35 and later ship credential-manager on more platforms, so manager may be configured even if you never chose it.

Triage order: erase the stored credential, verify the token with one API call, then check the helper that answers. When a workflow file or remote config is the suspect, the env reader shows which variables the job actually has, and the base64 encoder is a quick way to inspect the Basic auth header a request would send without printing the token itself.

Official references: Managing personal access tokens and gitcredentials.

Official references

primary documentation

The Git documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Git guides

More in Git

All Git guides

The guides filed next to this one in Git, in library order.