Pushing to GitHub via. Git

Resolving a 'Permission Denied (publickey)' error

When I first committed to actually publishing a blog and settled on using Hugo and Github, I ran into a problem when trying to actually synchronize my local repository with Github: I kept getting a ‘Permission Denied (publickey)’ error when I pushed the content up to Github. After some Google-fu, I found that the error was because I didn’t have any SSH keys setup on my Windows 10 system and it couldn’t communicate securely with GitHub.

Here’s how I fixed that:

  1. Open git bash. I could have done this in Windows Terminal (by creating a new profile linked to git bash), but since this is a one-time task, I didn’t bother.
  2. Type cd ~/.ssh. This will take you to the root directory for Git (likely C:\Users\username\.ssh\)
  3. Within the .ssh folder, there should be two files: id_rsa and id_rsa.pub. Type ls to see a directory listing. These are the files that tell your computer how to communicate with GitHub. If those two files don’t show up, continue to #4.
    NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git and GitHub to recognize them by default.
  4. Since the SSH keys don’t exist yet, create thethem: type ssh-keygen -t rsa -C "you@email.com". This will create both the id_rsa and id_rsa.pub files.
  5. Open id_rsa.pub in your favorite text editor Notepad.
  6. Copy the contents (exactly as it appears, with no extra spaces or lines) of id_rsa.pub and paste it into GitHub under the Account Settings > SSH Keys page.

Now that you’ve added your public key to Github, try to git push again and see if it works. It should!

A step-by-step rundown of this process (and more!) is also on the GitHub site: Connecting to GitHub with SSH

Built with Hugo
Theme Stack designed by Jimmy