Skip to content

Permission Denied (Publickey)

Error message

                [email protected]: Permission denied (publickey).
              

Quick summary

Your SSH key is not configured correctly or is not associated with your GitHub account, so the remote rejects your connection.

Why this happens

  • No SSH key was generated or added to your SSH agent

  • The SSH key is not added to your GitHub account

  • The SSH agent is not running or does not have your key loaded

  • Wrong remote URL format (using SSH when you should use HTTPS)

Minimal example

✗ Broken code
git push origin main  # [email protected]: Permission denied (publickey).
✓ Fixed code
# Generate and add SSH key
ssh-keygen -t ed25519 -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy ~/.ssh/id_ed25519.pub to GitHub Settings > SSH
git push origin main  # now succeeds

Generate an SSH key, add it to the SSH agent and your GitHub account, then push will work.

How to diagnose

  • Test SSH connection: ssh -T [email protected]

  • Check for SSH keys: ls -al ~/.ssh

  • Verify the SSH agent is running: ssh-add -l

  • Check the remote URL: git remote -v

How to fix

  • Generate an SSH key: ssh-keygen -t ed25519 -C '[email protected]'

  • Add the key to the SSH agent: ssh-add ~/.ssh/id_ed25519

  • Add the public key to GitHub: copy ~/.ssh/id_ed25519.pub and add it in GitHub Settings > SSH keys

  • Or switch to HTTPS: git remote set-url origin https://github.com/user/repo.git

How to prevent

  • Set up SSH keys when you first configure Git

  • Verify SSH access with ssh -T [email protected] before cloning

Related Resources

Related Glossary

Related Lessons

← Back to language