/github-for-non-tech

How to fix “permission denied” error on GitHub?

Learn how to fix GitHub’s “Permission Denied” error with our step-by-step guide. Check your SSH keys, update remotes, and adjust file permissions effortlessly.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to fix “permission denied” error on GitHub?

 
Step 1: Understand the “Permission Denied” Error
 

When you run a Git command that communicates with GitHub over SSH (for example git push), you may see an error like:


Permission denied (publickey).
fatal: Could not read from remote repository.

This means GitHub didn’t accept your SSH key. The most common causes are:

  • You don’t have an SSH key on your machine.
  • Your SSH key is not loaded into the SSH agent.
  • Your SSH key is not added to your GitHub account.
  • Your Git remote is using the wrong URL format.
  • Your private key file has incorrect permissions.

 
Step 2: Check for Existing SSH Keys
 

Verify if you already have SSH keys in your local machine:


ls -al ~/.ssh

Common key file names are id_rsa and id_rsa.pub or id_ed25519 and id_ed25519.pub. If you see at least one .pub file, you have an existing public key.

  • If you have a public key, go to Step 4.
  • If no keys exist, proceed to Step 3 to generate one.

 
Step 3: Generate a New SSH Key
 

Create a new SSH key using the ssh-keygen command:


ssh-keygen -t ed25519 -C "your\[email protected]"

When prompted:

  • Press Enter to accept the default file location.
  • Optionally provide a passphrase or press Enter for no passphrase.

This produces two files: your private key (~/.ssh/id_ed25519) and your public key (~/.ssh/id_ed25519.pub).

 
Step 4: Add Your SSH Key to the SSH Agent
 

Ensure the SSH agent is running and your key is loaded:


eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id\_ed25519
  • If you used a different filename, replace `id_ed25519` with your key’s name.
  • On Windows, you may need to start the SSH agent as a service or via Git Bash.

 
Step 5: Add Your SSH Key to Your GitHub Account
 

Copy the contents of your public key and add it to GitHub settings:


cat ~/.ssh/id\_ed25519.pub
  • Log in to GitHub and go to **Settings → SSH and GPG keys → New SSH key**.
  • Paste the key, give it a descriptive title, and click **Add SSH key**.

 
Step 6: Update Your Git Remote to Use SSH
 

Verify your remote URL and switch to SSH if needed:


git remote -v

If you see an HTTPS URL (https://github.com/...), change it to SSH:


git remote set-url origin [email protected]:username/repo.git

Replace username/repo.git with your repository’s path.

 
Step 7: Test the SSH Connection
 

Run a test command to confirm authentication:


ssh -T [email protected]
  • A successful message looks like: Hi username! You've successfully authenticated...
  • If you still see “Permission denied,” proceed to Step 8.

 
Step 8: Fix File Permissions on Your Private Key
 

SSH requires strict permissions on your private key. Ensure only you can read it:


chmod 600 ~/.ssh/id\_ed25519

Then repeat Step 7 to test the connection again.

 
Step 9: Alternative—Use HTTPS or Personal Access Token
 

If SSH still fails, you can switch back to HTTPS and use a Personal Access Token (PAT):


git remote set-url origin https://github.com/username/repo.git
  • Generate a PAT under **Settings → Developer settings → Personal access tokens**.
  • Use the token instead of your password when Git prompts you.

You have now resolved the “Permission denied” error and can push, pull, and clone repositories on GitHub without issues.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022