Quick GitHub 'Permission denied (publickey)' SSH error fix
GitHub ‘Permission denied (publickey)’ error
If your attempt to clone a GitHub repository over SSH is foiled by GitHub’s Permission denied (publickey) SSH error, there’s usually a quick fix.
GitHub’s Permission denied (publickey) error is usually caused by one of the following three issues:
- You have used an incorrect email address in the GitHub SSH URL
- You have not configured your public SSH key in your GitHub account
- You must create GitHub SSH keys to be used by the secure shell
Always use [email protected]
An SSH URL for my rock-paper-scissors repository looks like this:
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.
Do not change the email address. It must be: [email protected]
|Git SSH Keys Tutorials|
Further your knowledge with these Git and SSH tutorials:
Follow these tutorials and you’ll learn GitHub Actions fast.
You can test the GitHub SSH connection for the Permission denied error by using 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...
GitHub SSH configuration
Your public SSH key must be registered in your account setting in order to avoid GitHub’s Permission denied (publickey) SSH error.
Confirm that your public key has been configured correctly by checking 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.
GitHub SSH key generation
One sure fire way to guarantee you’ll 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’ll need to 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 the GitHub SSH keys are created, 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 time connecting 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.