git 无法创建工作树目录“example.com”。:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20276895/
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-09-10 17:23:49  来源:igfitidea点击:

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

gitgithubnginxsshvps

提问by David Ingledow

I have got a virtual private server with nginx Virtual Hosts setup (Server Blocks).

我有一个带有 nginx 虚拟主机设置(服务器块)的虚拟专用服务器。

I've installed Git and got my ssh keys authenticated with GitHub.

我已经安装了 Git 并通过 GitHub 验证了我的 ssh 密钥。

I have my website running in

我的网站正在运行

 ~/var/www/example.com/public_html/

I tried to run:

我试着跑:

git clone [email protected]:example/example.co.uk.git

to pull my files on GitHub to the /public_html/ directory but I get the error:

将 GitHub 上的文件拉到 /public_html/ 目录,但出现错误:

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

I've followed this tutorial including the same issue he has mentioned on the page, but it still won't work: http://machiine.com/2013/pulling-a-git-repo-from-github-to-your-ubuntu-server/

我已经按照本教程包括他在页面上提到的相同问题,但它仍然不起作用:http: //machiine.com/2013/pulling-a-git-repo-from-github-to-your -ubuntu 服务器/

I'm completely new to this, so your help would be much appreciated!

我对此完全陌生,因此非常感谢您的帮助!

回答by Wil

I think you don't have your permissions set up correctly for /var/www Change the ownership of the folder.

我认为您没有为 /var/www 正确设置权限 更改文件夹的所有权。

sudo chown -R **yourusername** /var/www

sudo chown -R **yourusername** /var/www

回答by ashu Kr

I was facing the same issue but it was not a permission issue.

我遇到了同样的问题,但这不是许可问题。

When you are doing git clone it will create try to create replica of the respository structure.

当您执行 git clone 时,它​​将创建尝试创建存储库结构的副本。

When its trying to create the folder/directory with same name and path in your local os process is not allowing to do so and hence the error. There was "background" java process running in Task-manager which was accessing the resource of the directory(folder) and hence it was showing as permission denied for git operations. I have killed those process and that solved my problem. Cheers!!

当它尝试在本地操作系统进程中创建具有相同名称和路径的文件夹/目录时不允许这样做,因此会出现错误。在任务管理器中运行了“后台”java 进程,它正在访问目录(文件夹)的资源,因此它显示为 git 操作的权限被拒绝。我已经杀死了这些过程,这解决了我的问题。干杯!!

回答by Mahendrasinh Rana

I was facing same issue then I read first few lines of this question and I realised that I was trying to run command at the root directory of my bash profile instead of CD/my work project folder. I switched back to my work folder and able to clone the project successfully

我遇到了同样的问题,然后我阅读了这个问题的前几行,我意识到我试图在我的 bash 配置文件的根目录而不是 CD/我的工作项目文件夹中运行命令。我切换回我的工作文件夹并且能够成功克隆项目

回答by Sajid Malik

  1. Open your terminal.
  2. Run cd /
  3. Run sudo chown -R $(whoami):$(whoami) /var
  1. 打开你的终端。
  2. cd /
  3. sudo chown -R $(whoami):$(whoami) /var

Note: I tested it using ubuntu os

注意:我使用 ubuntu os 对其进行了测试

回答by Piyush Bansal

You should logged in not as "root" user.

您不应以“root”用户身份登录。

Or assign permission to your "current_user" to do this by using following command

或使用以下命令为您的“current_user”分配权限以执行此操作

sudo chown -R username.www-data /var/www

须藤 chown -R username.www-data /var/www

sudo chmod -R +rwx /var/www

须藤 chmod -R +rwx /var/www

回答by Jirson Tavera

Change ownership and permissions folder

更改所有权和权限文件夹

sudo chown -R username.www-data /var/www

sudo chmod -R +rwx /var/www

回答by trustidkid

Most common reason for this error is that you don't have permission to create file in the current directory. Ensure you are in the right directory. try this on mac system to list the directory

此错误的最常见原因是您无权在当前目录中创建文件。确保您位于正确的目录中。在mac系统上试试这个来列出目录

ls, then cd right_folder_name

ls,然后 cd right_folder_name

回答by m.sajjad.s

use this for all user

将此用于所有用户

sudo chown -R $(whoami):$(whoami) /var/..