Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh clone not working with github

Tags:

git

github

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 [email protected]: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 [email protected], 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?

like image 722
sabari Avatar asked Jul 20 '12 19:07

sabari


3 Answers

As per GitHub help, the error you're getting is related to wrong SSH configuration. Please follow indications for setting up SSH for GitHub and check accordingly.

like image 159
Mihai Maruseac Avatar answered Oct 07 '22 18:10

Mihai Maruseac


You can either follow the below document to add your key to ssh-agent https://help.github.com/en/articles/connecting-to-github-with-ssh

or you can run the following command to execute it temporarily

ssh-agent bash -c 'ssh-add ~/.ssh/github_rsa; git clone git://github.com/npsabari/testrepo.git'

like image 27
Chetan Pangam Avatar answered Oct 07 '22 20:10

Chetan Pangam


The reason for the error is that you don't have your public key (~/.ssh/id_rsa.pub) uploaded to GitHub. Add it to your account(you may do this through the web panel provided by github) and it will work.

like image 20
Lusitanian Avatar answered Oct 07 '22 20:10

Lusitanian