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:
- You have used an incorrect email address in the GitHub SSH URL
- You have not configured your public SSH key in your GitHub account
- 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.
- Open the Git Bash terminal or your preferred terminal.
- Check if
.sshfolder 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
- Enter the following command with a valid email address that you use for GitHub
ssh-keygen -t rsa -b 4096 -C "email@example.com"
- 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.
- 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.
- Two new files will be created in the
- 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.
- Copy the SSH key and go to your
SSH and GPG keysand paste it. Add title as you want for ex. My PC SSH Key
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.
- Change URL to HTTPS while cloning:
git clone https://github.com/USERNAME/REPOSITORY.git
- 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
- 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:
- Git Fetch All Branches
- Laravel: Switch Case Statement In Controller Example
- Laravel: Change Column Type In Migration
- 2fa Laravel With SMS Tutorial With Example
- How To Use Where Date Between In Laravel
- How To Add Laravel Next Prev Pagination
- Laravel Remove Column From Table In Migration
- Laravel: Get Month Name From Date
- Laravel: Increase Quantity If Product Already Exists In Cart
- How To Update Pivot Table In Laravel
- How To Install Vue In Laravel 8 Step By Step
- How To Handle Failed Jobs In Laravel
- Best Ways To Define Global Variable In Laravel
- How To Get Latest Records In Laravel
- How To Break Nested Loops In PHP Or Laravel
- How To Pass Laravel URL Parameter
- Laravel Run Specific Migration
- Laravel Notification Tutorial With Example
- How To Schedule Tasks In Laravel With Example
- 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!