1

I am trying to clone from Github to my server. I have created the public key and put it in deploy keys on the repository. I have used ssh-add to add it on the server, but am still getting this error: permisssion denied (publickey). ssh -T git@github.com works. What am I missing?

To clarify: I generated the public key on the server and put it on github, on the repository I want to clone. ssh -T git@github from the server works, cloning the repository does not.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
NigelLegg
  • 115
  • 1
  • 11
  • What url are you trying to clone? You need to clone the `ssh` url, not the `https` url. – Anshul Goyal Apr 10 '14 at 16:48
  • @mu無 The error wouldn’t show “permission denied (publickey)” if OP wasn’t using SSH. – poke Apr 10 '14 at 16:53
  • @NigelLegg Are the ssh keys in the same account, from which you try to do a clone? Also, If you are using multiple ssh keys and have to `ssh-add` everytime, check [this question](http://stackoverflow.com/questions/19207838/git-permission-denied-publickey-on-every-connect) – Anshul Goyal Apr 10 '14 at 16:59

1 Answers1

2

You need to copy your private key to the server, and not the public key.

Better still, generate ssh keys on the server and then copy the public key from there to github. As an aside, generate the ssh key without passphrase to avoid issues around passphrases.

Github supports multiple ssh keys, so you can have one ssh key from your local machine and another one from your server both added to same github account.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • Yes, generate the private key on the server *only*, and do not share or reuse the key elsewhere. Create a key for *each* machine, and add each public key separately to your GitHub account. That way you have full control over what has access. – poke Apr 10 '14 at 16:51