fatal: Authentication failed for '...'
Git’s “fatal: Authentication failed” means the remote server rejected your credentials — your token, password, or SSH key was not accepted by the server.
What It Means
Authentication failed means Git couldn’t prove who you are to the remote server. For HTTPS remotes, this means your username/password or personal access token was rejected. For SSH remotes, this means your SSH key wasn’t recognized by the server. In August 2021, GitHub removed support for password-based Git authentication over HTTPS — you must now use a personal access token (PAT) or SSH key.
Why It Happens
- You’re using a password on GitHub after they deprecated password authentication for Git operations.
- The personal access token has expired or was revoked.
- The SSH public key isn’t added to your GitHub/GitLab/Bitbucket account.
- The wrong SSH private key is being used by the SSH agent.
- Two-factor authentication is enabled and you’re using a password instead of a PAT.
- The credential manager (Windows Credential Manager, macOS Keychain) has stale credentials.
How to Fix It
Step 1: Use a personal access token (HTTPS)
Generate a token on GitHub:
GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)Then use the token as your password:
git clone https://github.com/user/repo.git
Username: your-username
Password: your-generated-tokenStep 2: Update stored credentials
On macOS (update Keychain):
git credential-osxkeychain erase
host=github.com
protocol=https
[press return twice]On Windows (update Credential Manager):
# Open Control Panel → Credential Manager → Windows Credentials
# Find git:https://github.com and update itOn Linux (disable credential helper):
git config --global --unset credential.helperStep 3: Switch to SSH authentication
Generate an SSH key and add it to your account:
ssh-keygen -t ed25519 -C "your-email@example.com"
cat ~/.ssh/id_ed25519.pub
# Add this to GitHub: Settings → SSH and GPG keys → New SSH keyThen update the remote URL:
git remote set-url origin git@github.com:user/repo.gitStep 4: Check which SSH key is being used
ssh -T git@github.com
# Should say: "Hi username! You've successfully authenticated..."If it uses the wrong key, add your key to the SSH agent:
ssh-add ~/.ssh/id_ed25519Step 5: Verify the remote URL format
git remote -v
# HTTPS should look like: https://github.com/user/repo.git
# SSH should look like: git@github.com:user/repo.gitBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro