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

Posted March 18, 2014 138.6k views
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 ----- 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 ----- I asked Digitalocean support but they were unable to help me. Any ideas on what's going on? Thanks.

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.

Submit an Answer
13 answers
Try specifying the private key with -i
git -i /path/to/your/private/key

Or you can edit ~/.ssh/config and add these lines:

User git
PreferredAuthentications publickey
Port 22
IdentityFile /path/to/your/private/key

[any other host you want to add]

After that you can just type:
git clone

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

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.
I recall `i` being an option for `ssh` but it doesn't appear to be a part of `git` according to man.

So, I created the file `/.ssh/config` and wrote the contents to it, changing the path to my key.

Still no luck.

Why does this happen only with DigitalOcean? I don't recall having this issue on Amazon, Hostgator, Linode and others.
Check the path,
The path should be /home/username/.ssh/config or ~/.ssh/config
but not /.ssh/config
Tony Tsang,
Sorry, I meant to type `~/.ssh/config`.
By the way, I even tried adding that info to `/etc/ssh/ssh_config`, no dice.
In any case, if `` resides in `~/.ssh`, git via SSH should pick the key up automatically.

Emilio Castro,
That's not necessary since these are all public repos. I only own that one repo, so if necessary, I can add the key but there are others I'm trying to clone but it doesn't work and I can't add my key to them because they are not my repositories and these are public repositories such as Twitter Bootstrap, for example (

$ cd /var/www
$ mkdir test
$ cd test
$ git clone
Cloning into 'bootstrap'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
You have to add the public key in order to access github through ssh.
I am experiencing this same issue and I have added my public key on Github.
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

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, 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.

Previous 1 2 Next