git authentication ai_generated true

fatal: Authentication failed for 'https://github.com/user/repo.git'

ID: git/authentication-failed

Also available as: JSON · Markdown
92%Fix Rate
94%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

Git cannot authenticate with the remote. Credentials may be wrong, expired, or the auth method is no longer supported.

generic

Workarounds

  1. 94% success Generate a personal access token (PAT) and use it instead of a password
    # GitHub: Settings > Developer Settings > Personal Access Tokens > Generate new token
    # Use the token as the password when git prompts for credentials.
    # Store it so you don't have to re-enter:
    git config --global credential.helper store

    Sources: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

  2. 90% success For SSH, test key with ssh -T and add to agent if needed
    # Test SSH connectivity:
    ssh -T [email protected]
    
    # If key not found, add it to the agent:
    eval $(ssh-agent -s)
    ssh-add ~/.ssh/id_ed25519
    
    # If no key exists, generate one:
    ssh-keygen -t ed25519 -C '[email protected]'
    # Then add the public key to GitHub/GitLab settings.

    Sources: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection

  3. 88% success Use credential helper to cache or store credentials securely
    # Cache credentials in memory for 1 hour:
    git config --global credential.helper 'cache --timeout=3600'
    
    # Store credentials on disk (less secure):
    git config --global credential.helper store
    
    # On macOS, use Keychain:
    git config --global credential.helper osxkeychain
    
    # On Linux, use libsecret:
    git config --global credential.helper /usr/libexec/git-core/git-credential-libsecret

    Sources: https://git-scm.com/docs/gitcredentials

Dead Ends

Common approaches that don't work:

  1. Retrying with the same password 95% fail

    If password auth is disabled (GitHub since Aug 2021), no password will work

Error Chain

Frequently confused with: