Question

Unable to clone Github repo via SSH protocol. HTTPS works.

  • Posted on March 18, 2014
  • housni.yAsked by housni.y

Hi, I have a very basic droplet setup. No firewalls or any sort of security measures are set up. It’s virtually open.

I wanted to clone a git repo but had some issues. Let me illustrate with an example:

$ cd /var/www $ mkdir test $ cd test $ git clone git@github.com:housni/li3_uploadable.git

The above gives me:

Cloning into ‘li3_uploadable’… Permission denied (publickey). fatal: Could not read from remote repository.

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

‘li3_uploadable’ is a public repo. I know this because I own it. Besides, I have this issue with all the other Github repos.

However, I noticed that cloning via HTTPS works:

git clone https://github.com/housni/li3_uploadable.git

I asked Digitalocean support but they were unable to help me. Any ideas on what’s going on?

Thanks.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I was getting this message, even though I had followed the guide at GitHub to the letter - including adding the public SSH key to their website https://help.github.com/articles/generating-an-ssh-key/

The issue was, out of habit I had been using using sudo in front of git commands i.e. sudo git pull. The SSH that was previously generated was in my home directory but putting sudo in front of it makes it look elsewhere for the key. So using just git pull makes it look within my home directory - it works great now!

You need to make sure that you have added the public key from your server to your Github repo first.

Try specifying the private key with -i <br>git -i /path/to/your/private/key git@github.com:repository/location <br> <br>Or you can edit ~/.ssh/config and add these lines: <br> <br>Host github.com <br> User git <br> Hostname github.com <br> PreferredAuthentications publickey <br> Port 22 <br> IdentityFile /path/to/your/private/key <br> <br>[any other host you want to add] <br> <br>After that you can just type: <br>git clone github.com:repository/location