Sub topic 17
Troubleshooting common authentication errors
This chapter assumes you can clone, commit, and push, and that you have set up either an HTTPS token or an SSH key as covered in earlier chapters. Most failures come from a small set of causes. The fastest fix starts with finding out which transport you are actually using.
Start by identifying the transport
Authentication errors look different over HTTPS and SSH, so check the remote URL first.
git remote -vA URL starting with https:// uses a token. A URL starting with [email protected]: uses an SSH key. You can switch between them with git remote set-url origin, which is often the quickest way to get around a problem on one side.
HTTPS errors
The most common message is remote: Invalid username or token. Password authentication is not supported for Git operations. GitHub no longer accepts account passwords for Git. Use a personal access token in the password prompt.
Work through these causes in order:
- Expired or revoked token. Check the token's status in your GitHub settings. Generate a new one if needed.
- Missing scope. A
403on push often means the token can read but not write. Give it write access to repository contents. - Stale cached credential. A credential helper may keep returning the old token. Remove the saved entry, then Git will prompt again.
- SAML SSO not authorized. If the repository belongs to an organization that uses SSO, authorize the token for that organization in the token settings.
- Wrong account. The token may belong to a user who cannot access the repository. GitHub often reports this as
repository not found.
To see which helper Git uses:
git config --global credential.helperIf it prints nothing, Git prompts every time. If it prints a helper, a bad entry stored there will be reused until you clear it.
SSH errors
The classic failure is Permission denied (publickey). It means GitHub did not accept any key your client offered. Test directly:
ssh -T [email protected]Success looks like Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access. If it fails, check these:
- Key not loaded. Run
ssh-add -l. If it lists nothing, runssh-add ~/.ssh/id_ed25519. - Public key not on GitHub. Compare your
.pubfile with the keys in your account settings. - Wrong key offered. With several keys, add a
Host github.comblock withIdentityFileandIdentitiesOnly yes. - SSO not authorized. For SSO organizations, authorize the key as well.
- Port 22 blocked. A timeout, rather than a permission error, suggests the network blocks the port. Use
ssh.github.comon port 443 in~/.ssh/config.
Exercise
Exercise
git push over SSH prints Permission denied (publickey). ssh-add -l says "The agent has no identities." What is the likely cause, and what do you run?
Show answer
The private key is not loaded into ssh-agent, so no key is offered to GitHub. Run ssh-add ~/.ssh/id_ed25519 (or your key path), then retest with ssh -T [email protected]. If it still fails, confirm the matching public key is added to your GitHub account.
Exercise
A push over HTTPS to an organization repository returns 403 even though your token is valid and has write scope. What should you check?
Show answer
Whether the organization enforces SAML SSO. If so, authorize the token for that organization in your token settings, then retry.