无法将我自己的存储库从github克隆到我的www文件夹

时间:2014-07-06 08:57:55

标签: git github clone

我正在使用linux mint。我是git的新手。我已将一个存储库从本地计算机推送到github。然后我重新安装了我的操作系统。现在我正在尝试克隆该repo并将其带回我的www文件夹。我可以在我的主文件夹中克隆它。但每当我尝试在我的www文件夹中克隆时,我都会收到此错误,说明权限已被拒绝。

这是我的命令

sudo git clone git@github.com:username/projectname.git /var/www/projectname/

我收到此错误

  

权限被拒绝(publickey)。致命:无法从远程读取   库中。

     

请确保您拥有正确的访问权限和存储库   存在。

1 个答案:

答案 0 :(得分:4)

您正在使用ssh网址,这意味着您需要重新创建自己的ssh密钥并将公开密​​钥添加到您的GitHub帐户。
请参阅" Generating SSH Keys"。

如果克隆无法与sudo一起使用,那是因为它会在~root/.ssh中查找这些键,而它们位于~yourUser/.ssh。 一个快速的解决方法至少要复制这些密钥:

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

更好的解决方案是为root生成一组不同的密钥,并将公共根ssh密钥注册到您的GitHub帐户。

" How can I run SSH as a different user on the same Ubuntu installation?"讨论了其他解决方案,包括this one

以root身份运行脚本,该脚本将使用git命令的用户环境:

su -lc "git clone git@github.com:username/projectname.git /var/www/projectname/" yourUser

这样,您就不需要复制密钥或生成新密钥。