Git and SSH

Fix "Permission denied (publickey)"

What to check when git push or ssh to GitHub says Permission denied (publickey).

Fill these in once
  1. See what GitHub says
    Terminal
    ssh -T git@github.com

    If it says "Hi username", SSH works and the problem is the repo address (step 4).

  2. Check a key is loaded
    Terminal
    ssh-add -l

    "The agent has no identities" means no key is loaded. Do the next step.

  3. Load your key
    Terminal
    ssh-add --apple-use-keychain ~/.ssh/id_ed25519

    No such file? You don't have a key yet. Create one with the SSH key page.

  4. Make sure the repo uses an SSH address
    Terminal
    git remote set-url origin git@github.com:username/project.git
  5. Still stuck? See the full conversation
    Terminal
    ssh -vT git@github.com

    Look for lines starting with "Offering public key" to see which keys were tried.

  1. See what GitHub says
    Terminal · Ubuntu / Debian
    ssh -T git@github.com

    If it says "Hi username", SSH works and the problem is the repo address (step 4).

  2. Check a key is loaded
    Terminal · Ubuntu / Debian
    ssh-add -l

    "Could not open a connection to your authentication agent" means the agent isn't running. Run eval "$(ssh-agent -s)" first.

  3. Load your key
    Terminal · Ubuntu / Debian
    ssh-add ~/.ssh/id_ed25519

    No such file? You don't have a key yet. Create one with the SSH key page.

  4. Make sure the repo uses an SSH address
    Terminal · Ubuntu / Debian
    git remote set-url origin git@github.com:username/project.git
  5. Still stuck? See the full conversation
    Terminal · Ubuntu / Debian
    ssh -vT git@github.com

    Look for lines starting with "Offering public key" to see which keys were tried.

  1. See what GitHub says
    PowerShell
    ssh -T git@github.com

    If it says "Hi username", SSH works and the problem is Git or the repo address (steps 4 and 5).

  2. Start the SSH agentRun as administrator
    PowerShell
    Get-Service ssh-agent | Set-Service -StartupType Automatic
    Start-Service ssh-agent
  3. Load your key
    PowerShell
    ssh-add "$env:USERPROFILE\.ssh\id_ed25519"
  4. Make sure the repo uses an SSH address
    PowerShell
    git remote set-url origin git@github.com:username/project.git
  5. Make Git use the same SSH as Windows
    PowerShell
    git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"

    Git for Windows ships its own SSH, which can't see keys loaded into the Windows agent.