Skip to content
fatal: Authentication failed for '...'

fatal: Authentication failed for '...'

DodaTech 3 min read

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-token

Step 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 it

On Linux (disable credential helper):

git config --global --unset credential.helper

Step 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 key

Then update the remote URL:

git remote set-url origin git@github.com:user/repo.git

Step 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_ed25519

Step 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.git
Why did GitHub stop accepting passwords for Git?
In August 2021, GitHub removed password authentication for Git operations over HTTPS due to security concerns. Passwords are less secure than tokens or SSH keys — tokens can be scoped, revoked individually, and rotated without changing your account password. Use a personal access token or SSH key for all Git operations on GitHub.
Can I use the same SSH key for multiple Git services?
Yes — you can add the same public SSH key to multiple services (GitHub, GitLab, Bitbucket). Each service stores your public key independently. However, for better security, consider using separate keys for each service. You can configure the SSH agent to use different keys for different hosts via ~/.ssh/config.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro