Permission Denied (Publickey)
Error message
git@github.com: 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
git push origin main # git@github.com: Permission denied (publickey).# Generate and add SSH key
ssh-keygen -t ed25519 -C "you@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy ~/.ssh/id_ed25519.pub to GitHub Settings > SSH
git push origin main # now succeedsGenerate 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 git@github.com
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 'your_email@example.com'
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 git@github.com before cloning