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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15696190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:36:02  来源:igfitidea点击:

Permission denied when cloning git repository

linuxgitgithubamazon-ec2git-clone

提问by coryj

So I just setup an Amazon EC2 instance. And installed git..

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

sudo yum install git

I then set up my ssh key with github. Now when I try to clone my repo into /var/www/html folder i get this error..

然后我用 github 设置了我的 ssh 密钥。现在,当我尝试将我的 repo 克隆到 /var/www/html 文件夹时,我收到此错误..

fatal: could not create work tree dir 'example.com'.: Permission denied

and when I run as root...

当我以 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.

But I made sure that my github public key matches my ~/.ssh/id_rsa.pub key. Is there something that I'm missing here?

但我确保我的 github 公钥与我的 ~/.ssh/id_rsa.pub 密钥匹配。有什么我在这里想念的吗?

采纳答案by nos

Your first error is because your user does not have access to write to /var/www/html . You could give your user permissions to do so.

您的第一个错误是因为您的用户无权写入 /var/www/html 。您可以授予您的用户这样做的权限。

Your second error when running as root, is likely that you have your ssh keys in your user home directory, not in /root/.ssh/ , or that your .ssh directory or the ~/.ssh/id_rsa.pub key file have improber permissions. ~/.ssh/ should have the permission bits 0700 , and should have ~/.ssh/id_rsa.pub e.g. 0600

以 root 用户身份运行时出现的第二个错误可能是您的 ssh 密钥位于用户主目录中,而不是 /root/.ssh/ 中,或者您的 .ssh 目录或 ~/.ssh/id_rsa.pub 密钥文件中有不当的权限。~/.ssh/ 应该有权限位 0700 ,并且应该有 ~/.ssh/id_rsa.pub 例如 0600

回答by joamag

Is the id_rsaprivate key in ~/.ssh/id_rsathe pair to you public key (~/.ssh/id_rsa.pub) ?

配对中的id_rsa私钥是~/.ssh/id_rsa您的公钥 ( ~/.ssh/id_rsa.pub) 吗?

If it's not (or you're not sure) I suggest you regenerate a new private/public key pair with ssh-keygen -t dsa.

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

回答by Drew Khoury

Have you tried this:

你有没有试过这个:

git: fatal: Could not read from remote repository

git:致命:无法从远程存储库读取

You can specify the username that SSH should send to the remote system as part of your remote's URL. Put the username, followed by an @, before the remote hostname.

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

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

回答by rasheednyc

My solution matches that of nos. Adding the public key of the root user fixes it. Another option would be changing the permission of the directory and executing the command as a regular user.

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

回答by outlawvikas

Note: this fix works for Mac users

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

Incase of macOS 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.

如果是 macOS 10.12.2 或更高版本,您需要修改 ~/.ssh/config 文件以自动将密钥加载到 ssh-agent 并将密码存储在您的钥匙串中。

Host *
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/<your_id_rsa>

Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

将您的 SSH 私钥添加到 ssh-agent 并将您的密码存储在钥匙串中。如果您使用不同的名称创建了密钥,或者如果您要添加具有不同名称的现有密钥,请将命令中的 id_rsa 替换为您的私钥文件的名称。

ssh-add -K ~/.ssh/<your_id_rsa>

ssh-add -K ~/.ssh/<your_id_rsa>

For more information please review https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

有关更多信息,请查看 https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent