Fix Git's SSH Permission Denied (PublicKey) Error on GitHub |Video upload date:  · Duration: PT6M37S  · Language: EN

Quick guide to fix Git SSH Permission Denied PublicKey errors on GitHub by creating keys adding to agent uploading the public key and testing the connectio

Check for an existing SSH key

Before you start generating keys like a hacker in a movie montage take a deep breath and look in your home directory for an SSH folder. Typical files are ~/.ssh/id_rsa and ~/.ssh/id_ed25519. If one of those exists you can skip key generation and move on to adding the key to an agent and uploading the public part to GitHub.

Generate a modern SSH key

Use a modern algorithm so future you does not hate past you. Ed25519 is a solid choice unless your organization demands legacy keys. Run this in a terminal and follow the prompts.

ssh-keygen -t ed25519 -C "your_email@example.com"

If you prefer RSA for some reason use a large size. Otherwise accept the default file name and set a passphrase if you want an extra layer of misery protection.

Add the private key to an SSH agent

The SSH agent stores your unlocked key so Git can use it without you typing the passphrase every five minutes. Start the agent and add your key.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Check the agent has your key with ssh-add -l. If you see nothing then the agent is not running or the key was not added.

Upload the public key to GitHub

Copy the public key file such as ~/.ssh/id_ed25519.pub and paste its contents into your GitHub profile under SSH and GPG keys. Give it a human readable name so the person who inherits your machine in ten years does not cry.

Verify your Git remote and file permissions

Make sure your repository remote is using SSH and not HTTPS. Run git remote -v and look for an SSH style entry described as git at github dot com followed by user slash repo dot git. If it shows HTTPS then change the remote to an SSH URL so publickey authentication is used.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

Strict permissions matter because SSH will refuse to use keys that are world readable. Also be aware of multiple SSH agents or credential helpers that can interfere with which key is offered.

Test the SSH connection and run debug

Talk directly to GitHub to see what the server thinks of your key. The verbose flag spits out the useful garbage that tells you whether the key was offered or ignored.

ssh -T -v git@github.com

Read the debug output for lines that show which identities were tried and whether an agent supplied a key. Common failure causes include the wrong key being used missing the key on GitHub or file permission problems.

Troubleshooting tips

  • Confirm the public key on GitHub matches the file on your machine
  • Run ssh-add -l to see what the agent is offering
  • If you use multiple keys configure ~/.ssh/config with Host entries to force the right key for github dot com
  • On Windows use Git Bash or WSL and follow the same steps or use the native credential manager if you prefer a GUI trap

Recap and final thoughts

In short check for an existing SSH key generate a modern key if needed add it to an SSH agent upload the public key to GitHub ensure your Git remote uses SSH secure your file permissions and run an SSH debug session. Follow those steps and the permission denied publickey error should stop haunting your commits. If it does not then the problem is probably something silly like a mismatched key or an agent you forgot to start.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.