Skip to content
FR
  1. LuzineDebug
  2. Git & GitHub
  3. [email protected]: Permission denied (publickey).
Git & GitHub Intermediate ≈ 10 min to fix

Fix "Permission denied (publickey)" with Git and GitHub

Error message
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  • [email protected]: Permission denied (publickey,keyboard-interactive).
  • [email protected]: Permission denied (publickey).
  • ERROR: Repository not found. fatal: Could not read from remote repository.
  • Load key "/home/user/.ssh/id_ed25519": bad permissions
  • Permissions 0644 for '/home/user/.ssh/id_ed25519' are too open.
In short

The Git server accepted none of the SSH keys your computer offered. Create a key with ssh-keygen -t ed25519, load it into the SSH agent, add the public key to your GitHub account, then check with ssh -T [email protected].

Be the first to confirm this fix

What this error means

With a URL like [email protected]:user/repo.git, Git uses SSH. The SSH client offers one or more private keys found in ~/.ssh or in the agent; the server looks for the matching public key in its accounts. Permission denied (publickey) means key authentication, the only accepted method, failed: no key was sent, the server does not know the key, or the key belongs to an account without access to the repository. The Could not read from remote repository line that follows is the Git-side consequence, not a separate error.

Common causes

  1. No SSH key, or key not added to the account: new machine, or a key generated but never pasted into GitHub > Settings > SSH and GPG keys.
  2. Key not loaded in the agent, or a non-standard file name that SSH does not try automatically.
  3. Wrong account: several GitHub accounts (personal / work) and SSH offers the key of the one without access to the repository.
  4. Command run with sudo: root uses its own keys (/root/.ssh), not yours.
  5. Permissions too open on ~/.ssh or the private key: SSH ignores the key ("bad permissions", "are too open").

Step-by-step fix

  1. Test the SSH connection

    Without sudo. If everything works, GitHub replies "Hi user! You’ve successfully authenticated, but GitHub does not provide shell access." The -v option shows which keys are tried.

    bash
    ssh -T [email protected]
    ssh -vT [email protected] 2>&1 | grep -E "Offering|Authenticated|identity file"
  2. Check for or create a key

    Look for an id_ed25519 / id_ed25519.pub pair. If there is none, create it and protect it with a passphrase. The command is the same on macOS, Linux and Windows (PowerShell).

    bash
    ls -al ~/.ssh
    ssh-keygen -t ed25519 -C "[email protected]"
  3. Load the key into the agent (macOS / Linux)

    On macOS, --apple-use-keychain stores the passphrase in the Keychain; also add the ~/.ssh/config block to make it automatic. On Linux, just use ssh-add ~/.ssh/id_ed25519.

    bash
    eval "$(ssh-agent -s)"
    ssh-add --apple-use-keychain ~/.ssh/id_ed25519
    
    # ~/.ssh/config
    Host github.com
      AddKeysToAgent yes
      UseKeychain yes
      IdentityFile ~/.ssh/id_ed25519
  4. Load the key into the agent (Windows)

    In PowerShell run as administrator, enable the OpenSSH Authentication Agent service, then add the key from a normal PowerShell.

    powershell
    Get-Service ssh-agent | Set-Service -StartupType Automatic
    Start-Service ssh-agent
    ssh-add "$env:USERPROFILE\.ssh\id_ed25519"
  5. Add the public key to GitHub

    Copy the .pub file (never the private key) and paste it into GitHub > Settings > SSH and GPG keys > New SSH key. With GitHub CLI, one command is enough. For an organisation repository with SSO, then click "Configure SSO" to authorise the key.

    bash
    # macOS
    pbcopy < ~/.ssh/id_ed25519.pub
    # Linux
    cat ~/.ssh/id_ed25519.pub
    # Windows (PowerShell)
    Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
    # or with GitHub CLI
    gh ssh-key add ~/.ssh/id_ed25519.pub --title "my-laptop"
  6. Fix permissions (macOS / Linux)

    If SSH reports "bad permissions" or "are too open", restrict access to the folder and the private key. Never make a private key world-readable.

    bash
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_ed25519
    chmod 644 ~/.ssh/id_ed25519.pub
  7. Alternative: switch to HTTPS

    If you cannot use SSH (corporate network, shared machine), switch the repository to HTTPS and sign in with gh auth login or Git Credential Manager. GitHub no longer accepts account passwords over HTTPS: you need a token or the credential manager.

    bash
    git remote set-url origin https://github.com/user/repo.git
    gh auth login

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • With several accounts, declare one alias per account in ~/.ssh/config (e.g. Host github-work with its own IdentityFile and IdentitiesOnly yes) and use it in the repository URL.
  • Never run git with sudo in your working folder; fix the folder ownership instead.
  • Protect each key with a passphrase and remove from GitHub the keys of machines you no longer use.

Frequently asked questions

Port 22 is blocked on my network, what can I do?

GitHub accepts SSH on port 443 through ssh.github.com. Add to ~/.ssh/config: Host github.com, Hostname ssh.github.com, Port 443, User git, then test again with ssh -T [email protected].

ssh -T works but git push still fails, why?

Either the repository uses an HTTPS URL (check git remote -v), or the key belongs to an account without write access to that repository, or the organisation requires SSO authorisation of the key.

RSA or Ed25519?

Ed25519 is recommended: shorter, fast and secure. If an old server does not support it, use ssh-keygen -t rsa -b 4096.

Useful tools for this error

More Git & GitHub errors

All Git & GitHub errors →