How do I fix 'Permission denied (publickey)' error when pushing to GitHub?
This error occurs due to missing SSH key authentication. Ensure your SSH key is added to GitHub and configured on your machine.
The 'Permission denied (publickey)' error is a common issue with SSH authentication, indicating GitHub doesn’t recognize your SSH key. First, check if an SSH key exists on your machine by navigating to ~/.ssh/
and looking for files like id_rsa.pub
or id_ed25519.pub
. If no key exists, generate one with ssh-keygen -t ed25519
or ssh-keygen -t rsa -b 4096
, and then copy the key using cat ~/.ssh/id_ed25519.pub
(or id_rsa.pub
). Next, add this key to your GitHub account by going to Settings > SSH and GPG keys > New SSH key. Paste the copied key here, naming it for easy reference. Now, configure SSH on your machine by running ssh-add ~/.ssh/id_ed25519
(replace with your key filename). Test the connection by running ssh -T [email protected]
; a successful connection message should appear. With the key added to GitHub and configured locally, you should now be able to push without permission issues.