5
votes

I came across a weird issue while cloning a git repository using ssh. I have the ssh setup:

ssh -T [email protected]
Hi yusufali2205! You've successfully authenticated, but GitHub does not provide shell access.

I am using the right clone url and have access to the repo I want to clone. But getting error:

➤ git clone [email protected]:<some-org>/<repo>.git
Cloning into 'project'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

There is no other message to debug what is wrong with my ssh setup or git configuration.

3

3 Answers

3
votes

I found out there was an entry in my .gitconfig which was replacing ssh with https.

[url "https"]
    insteadOf = git

I might have accidentally added this entry while using some tool. So the clone command was actually using the url [email protected]:<some-org>/<repo>.git

After removing the above entry from .gitconfig the problem was resolved.

2
votes

In my case, I had to delete ~/.ssh/known_hosts file, so that while cloning, it will remake that file. After this, it worked

0
votes

I was having the same problem and researching I tried something and I got it. Go to your .ssh directory, open the file known_hosts with the notepad, right at the beginning it has "github.com" ... insert SSH: at the beginning of github.com and it will look like this: "SSH: github.com" and save, try again. It worked for me!