【问题标题】:Git push changing ownership of files causing 500 server errorGit推送更改文件的所有权导致500服务器错误
【发布时间】:2013-01-18 00:05:31
【问题描述】:

git push 问题导致 500 服务器错误。根据服务器错误,似乎是文件权限问题。每次我从本地机器执行 git push 时,文件的所有权都会发生变化。

为了让事情重新开始,我必须进入 public_html 文件夹和chown potter.potter * -R

有人可以帮我吗?我在下面展示了我是如何设置的......

我在我网站的开发服务器上的 /home/username/gitrepos 中建立了一个名为 potter.git 的存储库

ssh root@potter.com

git config --global user.email "harry@potter.com"  
git config --global user.name "harry"  

在 /home/potter/gitrepos 中

mkdir potter.git  
cd potter.git  
git init --bare

设置挂钩以允许部署

cd hooks  
pico post-receive 

在 post-receive 钩子中输入以下内容以允许部署

#!/bin/bash
#
docroot="/home/potter/public_html"
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`

if [ "master" == "$branch" ]; then
git --work-tree=$docroot checkout -f $branch
fi

done

使接收后可执行

chmod 755 post-receive

在 .bash-profile 中设置工作目录

# GIT  
export GIT_DIR=/home/potter/potter.git  
export GIT_WORK_TREE=~/public_html

现在在我的本地机器上,我设置远程连接如下:

git remote add website ssh://root@potter.com/home/potter/potter.git 

要推送,我会执行以下操作:

git push website master

【问题讨论】:

    标签: linux git terminal


    【解决方案1】:

    文件所有者是执行结帐的人,因此这将是您连接到的用户。而且由于您连接到 root,所有文件都归 root 所有。

    首先我不会使用 root 作为 git 用户。我会专门为该任务创建一个新用户。

    其次,我将禁用通过 ssh 的 root 登录。如果你想扮演上帝,请使用susudo

    第三,如果您想以其他用户身份运行脚本(例如结帐脚本),您可以使用 ssh 连接到 localhost (potter@localhost) 上的正确用户,并使用公钥身份验证登录密码。您可以指定 ssh 应在登录后立即执行的命令。因此,您可以在 homedir 的某个位置创建一个脚本,更改为正确的目录并运行 git checkout。

    【讨论】:

    • 感谢您的建议。我创建了一个新用户“git”并将 gitrepos 文件夹更改为“git”而不是 root。现在......当我使用 'git@potter .....' 进行 git push 时,我不会再出现 500 个服务器错误吗?
    • 当您遵循我的第三条建议时,您不应再因权限错误而出现内部服务器错误 (500)。
    【解决方案2】:

    我注意到在 Centos 上使用 cPanel 时,如果文件所有权设置不正确,那么 apache 会抛出 500 错误。代码或文件权限设置可能没有问题。

    你可以像我一样创建一个钩子。

    在运行任何拉取后运行此文件以快速重置任何文件所有权。 当您运行它时,请确保您在要更新的目录中。

     #!/bin/bash
        for file in `ls -a | grep -v '^\.'`
        do
                if [[ -d $file ]]
                then
                        fowner=`ls -ld $file | awk '{print $3}'`
                        fgroup=`ls -ld $file | awk '{print $4}'`
                        chown -R $fowner:$fgroup $file
                fi
        done
    

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 1970-01-01
      相关资源
      最近更新 更多