Git file ownership change causing 500 server error
Problems with git push causing 500 server errors. It looks like the file issue is resolved according to server errors. the ownership of the files changes every time I push git from my local machine.
To work again, I have to go into the public_html folder and chown potter.potter * -R
Can anyone help me? I showed below how I defined ...
I have set up a repository called potter.git on my website development server at / home / username / gitrepos
ssh root@potter.com
git config --global user.email "harry@potter.com"
git config --global user.name "harry"
inside / home / potter / gitrepos
mkdir potter.git
cd potter.git
git init --bare
deployment hooks for deployment
cd hooks
pico post-receive
Introduced below in post-receive hook to allow deployment
#!/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
made a post-fetch executable
chmod 755 post-receive
set working directories in .bash profile
# GIT
export GIT_DIR=/home/potter/potter.git
export GIT_WORK_TREE=~/public_html
Now on my local machine, I have established a remote connection like this:
git remote add website ssh://root@potter.com/home/potter/potter.git
and push, I do the following:
git push website master
source to share
The owner of the file is whoever is performing the check, so this will be the user you are connecting with. And since you are connecting to root, all files are owned by root.
At first, I would not use root as a git user. I would create a new user specifically for this task.
Secondly, I would disable root login via ssh. Use su
or sudo
if you want to play God.
Third, if you want to run the script as a different user (like a checkout script), you can ssh connect to the correct user on localhost ( potter@localhost
) and use public key authentication to log in without a password. You can specify a command that ssh should execute right after login. So somewhere in your homedir you can create a script that will change to the correct directory and run a git checkout.
source to share