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:
- 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. - Type
cd ~/.ssh
. This will take you to the root directory for Git (likely C:\Users\username\.ssh\) - Within the
.ssh
folder, there should be two files:id_rsa
andid_rsa.pub
. Typels
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. - Since the SSH keys don’t exist yet, create thethem: type
ssh-keygen -t rsa -C "you@email.com"
. This will create both theid_rsa
andid_rsa.pub
files. - Open
id_rsa.pub
inyour favorite text editorNotepad. - 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