git@github: permission denied (PublicKey) SSH error fix

How to fix GitHub’s [email protected] ‘Permission denied (publickey)’ error

To fix GitHub’s Permission denied to [email protected] (publickey) error, you must address one of the following three causes:

  1. You used an incorrect email address in the GitHub SSH URL.
  2. You have not configured your public SSH key in GitHub.
  3. You have not created GitHub SSH keys to be used by the secure shell.

Always use [email protected] for SSH

As an example, here’s the SSH URL for my rock-paper-scissors repository:

[email protected]:cameronmcnz/rock-paper-scissors.git

The preamble of the SSH URL must be [email protected]. Some users incorrectly use their GitHub account email, or substitute their username where the first git is. That’s incorrect.

Do not change the email address. It must be: [email protected]

To test the GitHub SSH connection for the Permission denied error, use the -T switch. If SSH is set up correctly, the output includes a reference to your username:

C:\fix\permission\denied> ssh -T [email protected]
Hi cameronmcnz! 
GitHub SSH authentication is successful...
Git SSH keys tutorials

Further your knowledge with these Git and SSH tutorials:

Follow these tutorials and you’ll learn GitHub Actions fast.

GitHub SSH configuration

Your public SSH key must be registered in your account setting to avoid GitHub’s Permission denied (publickey) SSH error.

To confirm that your public key has been configured correctly, check the SSH and GPG link in your account settings. If no keys are listed, add your public key and try to connect to GitHub over SSH again. The error should go away.

setup github ssh key

If you don’t register your public key in the admin console, you will definitely encounter GitHub’s Permission denied (publickey) error with SSH.

GitHub SSH key generation

One sure-fire way to see GitHub’s Permission denied (publickey) error is if you don’t have any SSH keys at all.

Check for the .ssh folder under the user’s home directory. Regardless of whether you run on Windows or Linux, there should be a public and private key file in this folder. If it is empty, you must create an SSH keypair and then register the public key in GitHub.

C:\fix\permission\denied> ssh-keygen -o -t rsa -C "[email protected]"

Once you create the GitHub SSH keys, copy the value of the public key and configure it in your GitHub account settings. Then attempt to SSH to GitHub again.

It’s always frustrating when you encounter an error, especially when it’s your first attempt to connect to a remote resource.

Fortunately, if you’ve hit GitHub’s Permission denied (publickey) SSH error, follow one of the three resolutions suggested above and that should fix the problem.