Question

I'm trying to set up git on my VPS for the first time. I'm also using Virtualmin. Everything is installed and works well when I use root to push, but I obviously don't want to do that. The problem is, if I try to set up my 'git' user to push to my public_html directory, I get the following error:

remote: fatal: Could not switch to '/path/to/': Permission denied
error: unpack failed: unpack-objects abnormal exit

I'm assuming this is because my git user doesn't have permission to access the folder in which the public_html folder lives. Is there something I can add to my post-receive hook to call sudo or something else so that I don't have this problem. (Sorry, I know this is probably a super easy question, but this is my first time setting it up myself and I couldn't find a good answer through search).

Was it helpful?

Solution

You can just change the ownership. This is preferable:

$ sudo chown -R git-user:git-group /path/to

Or, add yourself to the group that currently owns it:

$ sudo usermod -a -G owner-group user

And if that doesn't work, just loosen up the permissions a bit:

$ sudo find /path/to/ -type f -exec chmod 664 {} + && sudo find /path/to/ -type d -exec chmod 775 {} +

FYI: the digits represent Owner Group Other - thus - 664 means the Owner and Group can read + write, while other can only read.

Such permissions are useful for when you have a group working on a file system.

If you are the only person, then that first command should do the trick just fine -

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top