Linux Git无法创建文件权限被拒绝

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

Git unable to create file permission denied

linuxgitubuntu

提问by max_

I am using Amazon EC2 to host a website which is deployed to the server via git. I used this tutorial previously on the same kind of EC2 Ubuntu Linux Server instance, and it has worked flawlessly. However, when I try and push to the server, I receive the following error trace:

我正在使用 Amazon EC2 托管一个通过 git 部署到服务器的网站。我之前在同类型的 EC2 Ubuntu Linux Server 实例上使用过本教程,它运行完美。但是,当我尝试推送到服务器时,我收到以下错误跟踪:

Tutorial: http://toroid.org/ams/git-website-howto

教程:http: //toroid.org/ams/git-website-howto

Trace:

痕迹:

$ git push origin master

Counting objects: 5, done.
Writing objects: 100% (3/3), 250 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: unable to create file index.html (Permission denied)
To ssh://[email protected]/var/www/website.git
   8068aac..04eae11  master -> master

I only have one file inside the repository at the moment, which is index.html.

我目前在存储库中只有一个文件,即index.html.

The error trace is showing that the permission is being denied to create the file. Please can you tell me where I am going wrong?

错误跟踪显示创建文件的权限被拒绝。请你能告诉我我哪里出错了吗?

采纳答案by Nate C-K

You probably didn't do this part of the tutorial:

您可能没有执行本教程的这一部分:

First, the work tree (/var/www/www.example.org above) must be writable by the user who runs the hook (or the user needs sudo access to run git checkout -f, or something similar).

首先,工作树(上面的 /var/www/www.example.org)必须可由运行钩子的用户写入(或者用户需要 sudo 访问权限才能运行 git checkout -f 或类似的东西)。

回答by Peerkon

I believe if you run

我相信如果你跑

 sudo chown -R git:git /srv/git/ 

this is coming from How to fix permission denied for .git/ directory when performing git push?

这是来自如何在执行 git push 时修复 .git/ 目录的权限被拒绝?

回答by Frank Forte

FYI, I had this error because I made a hook to update files in a separate website root directory. For example:

仅供参考,我遇到了这个错误,因为我做了一个钩子来更新单独的网站根目录中的文件。例如:

/var/www/project.git  # (where we push updates)
/var/www/project.com  # (where the website exists)

I forgot to add the group permission to the project.com directory. This made it all work, index.html appeared in the /var/www/project.com directory once I did the next commit/push!

我忘记将组权限添加到 project.com 目录。这一切都奏效了,一旦我执行下一次提交/推送,index.html 就会出现在 /var/www/project.com 目录中!

Full code to make it work assuming you added your user to the "developers" group:

假设您将用户添加到“开发人员”组,使其工作的完整代码:

sudo chmod -R g+ws /var/www/project_name.git
sudo chgrp -R developers /var/www/project_name.git
sudo chmod -R g+ws /var/www/project_name
sudo chgrp -R developers /var/www/project_name

And the git setting for shared repository:

以及共享存储库的 git 设置:

git config core.sharedRepository group

回答by larrytech

Your anti virus or some ot her program may be preventing that file from being written to your folder. If you observe carefully, you would realize that all other files have been created except the one for which the permission is denied. You may be having a protection software that is preventing creation of certain file types and no matter the user type you are logged-in, the file won't be created until you disable that software.

您的防病毒程序或其他一些程序可能会阻止将该文件写入您的文件夹。如果您仔细观察,您会发现除了权限被拒绝的文件之外,所有其他文件都已创建。您可能有一个阻止创建某些文件类型的保护软件,无论您登录的用户类型如何,在您禁用该软件之前都不会创建该文件。

So check that your antivirus software isn't behind this for those running windows.

因此,请检查您的防病毒软件是否为运行 Windows 的用户提供支持。