Permission denied (publickey)
Git’s Permission denied (publickey) error means your SSH key wasn’t accepted by the remote server (GitHub, GitLab, Bitbucket, etc.), so the connection was refused before Git could authenticate you.
What It Means
When you use an SSH remote URL like git@github.com:user/repo.git, Git connects via SSH. SSH uses public-key cryptography: your machine holds a private key, and the server holds a matching public key. If the server doesn’t recognize your public key, or if SSH can’t find your private key, you get Permission denied (publickey).
Why It Happens
- You haven’t generated an SSH key pair yet.
- Your public key isn’t added to your GitHub/GitLab/Bitbucket account.
- The ssh-agent isn’t running or doesn’t have your key loaded.
- You’re using the wrong SSH key (e.g., a deploy key when you need a user key).
- Your SSH config is pointing to the wrong key file.
How to Fix It
1. Generate a new SSH key pair
ssh-keygen -t ed25519 -C "your-email@example.com"Press Enter to accept the default file location (~/.ssh/id_ed25519). Optionally add a passphrase for extra security.
2. Start the ssh-agent and add your key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed255193. Copy your public key
cat ~/.ssh/id_ed25519.pubSelect and copy the entire output — it starts with ssh-ed25519 (or ssh-rsa) and ends with your email.
4. Add the key to your Git provider
- GitHub: Settings → SSH and GPG keys → New SSH key → paste and save.
- GitLab: Preferences → SSH Keys → Add key → paste and save.
- Bitbucket: Personal settings → SSH keys → Add key → paste and save.
5. Test the connection
ssh -T git@github.comYou should see: Hi username! You've successfully authenticated...
6. Verify your remote URL uses SSH
git remote -vMake sure the URL starts with git@ (SSH), not https://. If it’s HTTPS, switch to SSH:
git remote set-url origin git@github.com:user/repo.gitBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro