【问题标题】:Prevent Git Push live master from changing file permission and ownership防止 Git Push live master 更改文件权限和所有权
【发布时间】:2021-01-13 12:41:59
【问题描述】:

我已经为此奋斗了好几天...每次我做git push live master(使用git post hook)...远程文件权限和所有权每次都被更改回默认值,这将使页面网站抛出 500 错误。我通常通过运行 sudo chown -Rf www-data:www-data /var/www/<Website-Root-Folder> 来解决这个问题,但我希望永久修复这个问题,所以我不必每次都这样做。

我做了以下,我在这里找到了:Permissions with Git Post-Receive

sudo usermod -a -G www-data root  // As I'm doing my push using the root user. 

对不起,我是 git、linux 的新手,不知道还能做什么。非常感谢您在每次推送后无需我运行此sudo chown -Rf www-data:www-data /var/www/<Website-Root-Folder> 即可完成这项工作的任何帮助。

谢谢

【问题讨论】:

  • www-data 用户添加到root 组,删除它不是一个好主意:deluser www-data root
  • 我收到了这个/usr/sbin/deluser: The user www-data is not a member of group root'. ...
  • 好的,运行groups www-data 以确认root 组没有出现
  • 我在运行groups www-data 后得到了这个www-data : www-data
  • 很好:用户www-data 仅在www-data 组中

标签: git digital-ocean


【解决方案1】:

您编写了一个脚本,该脚本在某些时候会执行 git checkout(或等效命令),它实际上会在您的目标文件夹中创建和更新文件。

您应该这样做,以便与您想要的用户一起运行此命令,例如:

sudo -u www-data git checkout ...

您可能需要设置 repo 本身的访问权限,以便用户 www-data 可以读取 repo:

  • 如果您的 repo 对所有用户都有 r 访问权限,那么您无需再做任何事情,

  • 您可以决定将该特定存储库中的所有文件组设置为www-data

    # in your post-receive script :
    chrgp www-data -R .
    
  • 或在该 repo 的目录上设置 setgid 位,以便在其中创建的文件和目录自动继承此目录的组(而不是用户组):

    # run once on your server, as root user :
    $ chmod -R g+s /path/to/repo.git
    $ chgrp -R www-data /path/to/repo.git
    
    $ ls -ld /path/to/repo.git
    drwxrwsr-x 9 root www-data 4096 janv. 13 14:20 repo.git
          ^
    # notice the 's' in the access rights
    

【讨论】:

  • 对不起,说到 /path/to/repo.git ...它是远程仓库还是桥仓库(即处理 git push live master 的空仓库)
  • 旁注:我更新了我的答案:如果您的文件和目录已经对所有用户拥有r 访问权限,则您无需设置任何其他内容
  • /path/to/repo.git :您将 post-receive 脚本放在服务器上的 repo 副本中,它就是那个 repo。
  • 我对这一切都是初学者,抱歉,如果我没有得到你。我不知道如何检查是否所有用户都有r 访问权限
  • 在我的 /var/repo/site.git/hooks 中的接收后文件中...里面有这个#!/bin/sh git --work-tree=/var/www/WEBSITEFOLDER --git-dir=/var/repo/site.git checkout -f ...这使得 /path/to/repo.git 你一直在指 /var/repo/site.git 吗?抱歉,我正在努力理解这一点
猜你喜欢
  • 2018-05-29
  • 2013-02-11
  • 2012-12-29
  • 2012-04-03
  • 2012-09-25
  • 1970-01-01
  • 2013-01-20
  • 2010-12-21
相关资源
最近更新 更多