Solving “Permission Denied” error on GitLab and GitHub

Originally published at adityatyagi.com

If you are landing on this article, I am sure you must have exhausted everything out there. From blogs to hitting random scripts from Stack Overflow. So, here is how I resolved this issue:

I did the same — hitting one script after the other to get it working, but as someone beautifully quoted:

6 hours of online surfing can save you 5 minutes of reading documentation

– Do not remember the author, but read it on Twitter

I was setting up multiple ssh keys on Windows 10 (which is a definite pain in the ass), as compared to setting it up on Linux/MacOS.

Stumbled upon this beautiful article by Megan Lo where she wrote detailed steps on: How To Set Up Multiple SSH Keys on Your Computer. Go through the article once just to check you have performed all the steps.

If you still aren’t able to get the solution, check Generating a new SSH key and adding it to the ssh-agent and ensure that your key (not the .pub file) but the key (private file) is added to the ssh agent.

Whenever you add your ssh key, be it the .rsa version or the .ed25519 version, both will generate two files:

  1. A public key — has the .pub extension
  2. A private key — without the .pub extension, but with the same name

You need to ensure that the private key is added to the ssh agent. To do that you need to first ensure that the ssh agent is running. In windows, you can do that by:

eval `ssh-agent -s`

Make sure you hit this in the git bash and not in powershell or cmd. It might give you error like “eval is not a identifiable term”.

If you get the ssh-agent pid like this Agent pid 1764, then you are good to go. The PID can be different than this one.

Next you need to add the private key to the ssh-agent. This step also has to be done in the git bash.

ssh-add ~/.ssh/id_ed25519_gitlab_nh

Use ssh-add along with complete path to your ssh private key. That’s it.

Try cloning the repo and you should be good to go!

(If by any chance you are still not able to resolve this, check this article from the official GitHub Docs: Error: Permission denied (publickey) ) and also this from the GitLab official docs

How to copy ssh key in windows?

This script in the git bash will copy the ssh key to clipboard so that you can paste it to GitHub or GitLab. Ensure you copy and paste the ssh key with .pub extension only, because that’s the “Public Key”. The other key has to be added to the ssh-agent, as seen above.

cat <complete_path_to_ssh_key>.pub | clip

For Linux

cat <complete_path_to_ssh_key>.pub | xclip

For MacOS

cat <complete_path_to_ssh_key>.pub | pbcopy

Originally published on adityatyagi.com

--

--

--

Programmer and a voracious reader who writes about web development | adityatyagi.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a beefy backend: our lessons from connecting 500k IoT devices

Explore the possibilities with hundreds of domain extensions — {link} -

Apache Spark Structured Streaming Via Docker Compose

The Best Android SDK Tools of The Year

Expert: How to Integrate Huawei Ads with GameAnalytics in Unity (Part-2)

Openstack Create Windows Server (2016/2019) Image(raw) — Part II

Doubling Down on Linked List — Part Two

How a SQL Statement is processed in Oracle?| Interview Q& A

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aditya Tyagi

Aditya Tyagi

Programmer and a voracious reader who writes about web development | adityatyagi.com

More from Medium

AWS: Run an S3 triggered Lambda Locally Using LocalStack

How to use mountebank in the real world mocking service

Generating SDKs for your API

Embedded vs Referenced Documents in MongoDB: How To Choose Correctly For Increased Performance