ssh clone not working with github

Viewed 78720

I am new to Git and GitHub.

I created a new repository and tried to clone on my local machine.

It worked for https and git-readonly URLs. That is, the following worked fine:

  • git clone https://github.com/npsabari/testrepo.git
  • git clone git://github.com/npsabari/testrepo.git

But when I tried git clone git@github.com:npsabari/testrepo.git, it didn't work. It gave the following error message:

Cloning into 'testRepo'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

And then I tried ssh git@github.com, but I got the error:

"Permission denied (publickey)."

instead of the welcome message.

What should I do to fix this? What is the reason for the error?

7 Answers

I would like to add that if you need to use sudo, it could interfere as the SSH key is not bound to that user. You might want to edit the rights before using git rather then after.

There are two ways to clone.
1. SSH
2. HTTPS
In my case first one had given similar issue as you got, but then I tried using HTTPS way by running following commands.
git clone https://xyz
Before that run this command git remote -v. This should show
1. git-url(fetch)
2. git-url(push)
If you see these both upon running command, it tells you that you got push right as well fetch rights. After you have configured, and set proxy properly, if you still find problem, this solution I have explained should work. If your SSH public key and private key are wrong then, you must fix that first before anything else.

Related