odbhut.shei.chhele
odbhut.shei.chhele

Reputation: 6254

Cannot clone my own repository from github to my www folder

I am using linux mint. I am new to git. I have pushed one repository from my local computer to github. Then I have reinstalled my os. Now I am trying to clone that repo and bring it back to my www folder. I can clone it in my home folder. But whenever I try to clone in my www folder then I get this error saying permission denied.

Here is my command

sudo git clone [email protected]:username/projectname.git /var/www/projectname/

I get this error

Permission denied (publickey). fatal: Could not read from remote repository.

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

Upvotes: 0

Views: 3119

Answers (1)

VonC
VonC

Reputation: 1324937

You are using an ssh url, which means you need to re-create your ssh keys and add the public one to your GitHub account.
See "Generating SSH Keys".

If the clone doesn't work with sudo, it is because it will look for those keys in ~root/.ssh, whereas they are in ~yourUser/.ssh.
One quick workaround would at least to copy those keys:

sudo cp /home/yourUser/.ssh/id_* /root/.ssh/

A better solution would be to generate a different set of keys for root, and register the public root ssh key to your GitHub account.

Other solutions are discussed at "How can I run SSH as a different user on the same Ubuntu installation?", including this one:

Running a script as root, which will use the user environment for the git command:

su -lc "git clone [email protected]:username/projectname.git /var/www/projectname/" yourUser

That way, you don't need to duplicate keys or generate new ones.

Upvotes: 4

Related Questions