Question

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

  • Posted March 18, 2014

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.

Subscribe
Share

You need to add your public key to GitHub in order to clone through SSH – even if it is a public repo. Why? Because git needs to authenticate though SSH to GitHub’s servers in order to do the clone. And in order to do that, they need to have your public key.

You need to add your public key to GitHub in order to clone through SSH – even if it is a public repo. Why? Because git needs to authenticate though SSH to GitHub’s servers in order to do the clone. And in order to do that, they need to have your public key.

Thanks, It worked for me thanks a lot


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

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.

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

I had SSH setup correctly and still got this error. The problem was not SSH, but simply folder permissions. The folder I was trying to clone into was owned by the root user (check this using ls -l), and using sudo is not valid when cloning a git repo. I had to change the folder to be owned by my user, like this: sudo chown -R $USER:$USER <path_to_folder>

Hi

I had the exactly same problem! I tried to clone a public git repo (using ssh) from two different computers (macs). In one computer it worked but it didn’t work in another. The only difference was: in one computer I was using zsh (in this one, the clone didn’t work) and in bash in another (it worked on this). When I changed from zsh to bash in the machine that didn’t work and tried cloning, it worked!! :)

I don’t know why. Maybe is some problem with zsh.

Hi, I encountered this issue too. But after I disconnected my VPN, it worked.

After you generated your ssh keys, there are only two files under ~/.ssh folder which are id_dsa and id_dsa.pub, but after you successfully connected to a server, another file known_hosts will be added.

Maybe you can add that file manually. But I am sorry I don’t know how to generate that file.

I observed the same issue : Below steps worked for me From Terminal - > Type ssh-add -l If the output is :The agent has no identities.

Enter: ssh-add ~/.ssh/id_rsa

This command should add your keys to the local ssh-agent. Once it is been added , Try git clone <git@github.com__repo_path__>

I am experiencing this same issue and I have added my public key on Github.

You have to add the public key in order to access github through ssh.