Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 克隆git存储库时权限被拒绝_Linux_Git_Github_Amazon Ec2_Git Clone - Fatal编程技术网

Linux 克隆git存储库时权限被拒绝

Linux 克隆git存储库时权限被拒绝,linux,git,github,amazon-ec2,git-clone,Linux,Git,Github,Amazon Ec2,Git Clone,所以我只是设置了一个AmazonEC2实例。并安装了git sudo yum install git 然后我用github设置ssh密钥。现在,当我尝试将我的repo克隆到/var/www/html文件夹时,我遇到了这个错误 fatal: could not create work tree dir 'example.com'.: Permission denied 当我以root身份运行时 Cloning into 'example.com'... Permission denied (p

所以我只是设置了一个AmazonEC2实例。并安装了git

sudo yum install git
然后我用github设置ssh密钥。现在,当我尝试将我的repo克隆到/var/www/html文件夹时,我遇到了这个错误

fatal: could not create work tree dir 'example.com'.: Permission denied
当我以root身份运行时

Cloning into 'example.com'...
Permission denied (publickey).
fatal: Could not read from remote repository.

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

但是我确保我的github公钥与我的~/.ssh/id\u rsa.pub密钥匹配。这里有我遗漏的东西吗?

~/.ssh/id\u rsa
中的
id\u rsa
私钥对您的公钥(
~/.ssh/id\u rsa.pub


如果不是(或者您不确定),我建议您使用
ssh-keygen-t dsa

重新生成新的私钥/公钥对。您的第一个错误是因为您的用户没有写入/var/www/html的权限。您可以授予用户这样做的权限

以root用户身份运行时出现的第二个错误可能是您的ssh密钥位于用户主目录中,而不是在/root/.ssh/中,或者您的.ssh目录或~/.ssh/id\u rsa.pub密钥文件具有取消权限。~/。ssh/应该具有权限位0700,并且应该具有~/.ssh/id_rsa.pub,例如0600,您是否尝试过此操作:

您可以指定SSH应该作为远程URL的一部分发送到远程系统的用户名。将用户名后跟@放在远程主机名之前

git remote set-url website abc@***.com:path/to/repo

我的解决方案与nos的解决方案相匹配。添加根用户的公钥可以修复它。另一个选项是更改目录的权限,并以普通用户的身份执行命令。

注意:此修复程序适用于Mac用户

在macOS 10.12.2或更高版本中,您需要修改~/.ssh/config文件,以自动将密钥加载到ssh代理中,并在密钥链中存储密码短语

Host *
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/<your_id_rsa>
主机*
是的
使用钥匙链是的
IdentityFile~/.ssh/
将您的SSH私钥添加到SSH代理,并将您的密码短语存储在密钥链中。如果您使用不同的名称创建了密钥,或者您正在添加具有不同名称的现有密钥,请将命令中的id_rsa替换为私钥文件的名称

ssh添加-K~/.ssh/

有关更多信息,请查看

因此,如果我的/root(/root/.ssh)中没有/.ssh目录,我应该创建它,然后创建ssh-keygen等等。。从那里?现在cd~/.ssh将我带到我的key@coryjacik你可以这么做,是的。尽管最佳实践会说您不应该作为root用户来做这些事情。最好将/var/www/html组更改为您的用户所属的组,并授予该组访问该目录的权限。