How do I fix the 'Permission denied (publickey)' error when pushing to GitHub?
This error happens when SSH keys are misconfigured or not linked to your GitHub account. Verify your key setup and add it to GitHub to resolve.
The 'Permission denied (publickey)' error appears when GitHub’s SSH authentication cannot verify your identity, often due to a missing or unlinked SSH key. Start by generating a new SSH key if you haven’t done so already (ssh-keygen -t rsa -b 4096 -C '[email protected]'
) and add the generated public key to your GitHub account under Settings > SSH and GPG keys. Use ssh-add ~/.ssh/id_rsa
to add your private key to the SSH agent. Next, test your SSH connection with ssh -T [email protected]
to confirm that authentication works. If you receive a successful message, retry your push. If you’re still encountering issues, ensure that your SSH config file (~/.ssh/config
) has entries for GitHub, specifying the correct IdentityFile and Host details. This configuration enables seamless, permission-granted access for future operations.