Home » Git Permission Denied Public Key Quick Fix

Git Permission Denied Public Key Quick Fix

Last updated on May 29, 2022 by

In this tutorial, we will see how to solve the Git permission denied public key error. If you try to clone the Github repository or run any Git commands on the Github repository, you might get this error. Let’s see why it’s causing this error and its solution?

Why Git Permission Denied Public Key Error Occurred?

The Git permission denied public key error is usually caused by one of the following three issues:

  1. You have used an incorrect email address in the GitHub SSH URL
  2. You have not configured your public SSH key in your GitHub account
  3. You must create GitHub SSH keys to be used by the secure shell

Solution 01 Generate Github SSH Key

SSH Key is a Secure Shell protocol suite found on Unix, Unix-like, and Microsoft Windows computer systems used to establish secure shell sessions between remote computers over insecure networks.

Let’s generate an SSH key in your PC.

  1. Open the Git Bash terminal or your preferred terminal.
  2. Check if .ssh folder is present or not in /home/<user>/ directory. If folder does not exists then create it by using the following command.
mkdir -p .ssh
chmod 0700 .ssh
create ssh folder is not exists
  1. Enter the following command with a valid email address that you use for GitHub
cd .ssh/
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  1. You will see the following in your terminal Generating public/private rsa key pair. When it prompts to "Enter a file in which to save the key (/home/<your username>/.ssh/id_ras)" press Enter. This accepts the file name.
  2. At the prompt, "Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don’t want to Enter the same passphrase again: [Type passphrase again] press enter again.
  3. Two new files will be created in the .ssh folder named id_rsa.pub & id_rsa
generate ssh key
  1. Now run the below command to read the file so that we can copy the content and paste it into the GitHub account and we are done.
cat id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQB/nAmOjTmezNUDKYvEeIRf2YnwM9
/uUG1d0BYsc8/tRtx+RGi7N2lUbp728MXGwdnL9od4cItzky
/zVdLZE2cycOa18xBK9cOWmcKS0A8FYBxEQWJ/q9YVUgZbFKfYGaGQxsER+A0w
/fX8ALuk78ktP31K69LcQgxIsl7rNzxsoOQKJ/CIxOGMMxczYTiEoLvQhapFQMs3FL
96didK/QbrfB1WT6s3838SEaXfgZvLef1YB2xmfhbT9OXFE3FXvh2UPBfN+ffE7iiay
Qf/2XR+8j4N4bW30DiPtOQLGUrH1y5X/rpNZNlWW2+jGIxqZtgWg7lTy3mXy5x8
36Sj/6Lyouremail@example.com
  1. Copy the SSH key and go to your GitHub account > Settings > SSH and GPG keys and paste it. Add title as you want for ex. My PC SSH Key
generate and add ssh key in github account

That’s it. Now, just try to clone the GitHub repo or perform any actions you want to perform.

Solution 02 Use HTTPS Instead Of SSH Protocol

We suggest using the first solution, but if you would like to go with an alternate solution then you can follow this.

So use the HTTPS instead of the SSH protocol to quick fix the Git permission denied public key error.

  1. Change URL to HTTPS while cloning:
git clone https://github.com/USERNAME/REPOSITORY.git
Git Permission Denied Public Key Quick Fix
  1. If you already have cloned repository on your machine then you can reset SSH Github URL to HTTPS Github URL by running the below command.
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
  1. You can verify the cloned URL by running the below command:
git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

Additionally, read our guide:

  1. Git Fetch All Branches
  2. Laravel: Switch Case Statement In Controller Example
  3. Laravel: Change Column Type In Migration
  4. 2fa Laravel With SMS Tutorial With Example
  5. How To Use Where Date Between In Laravel
  6. How To Add Laravel Next Prev Pagination
  7. Laravel Remove Column From Table In Migration
  8. Laravel: Get Month Name From Date
  9. Laravel: Increase Quantity If Product Already Exists In Cart
  10. How To Update Pivot Table In Laravel
  11. How To Install Vue In Laravel 8 Step By Step
  12. How To Handle Failed Jobs In Laravel
  13. Best Ways To Define Global Variable In Laravel
  14. How To Get Latest Records In Laravel
  15. How To Break Nested Loops In PHP Or Laravel
  16. How To Pass Laravel URL Parameter
  17. Laravel Run Specific Migration
  18. Laravel Notification Tutorial With Example
  19. How To Schedule Tasks In Laravel With Example
  20. Laravel Collection Push() And Put() With Example

That’s it from our end. We hope this article helped you solve the Git permission denied public key issue.

Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you for reading this post 🙂 Keep Smiling! Happy Coding!

 
 

Leave a Comment