3

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).

thesublimeobject
  • 1,393
  • 1
  • 17
  • 22
  • I've had this problem in several scenarios. If you want me to elaborate on my answer a bit, just let me know. – rm-vanda Mar 15 '14 at 01:08
  • Thanks a ton, I am going to try it out, and I'll let you know if I can't get it to work. – thesublimeobject Mar 15 '14 at 01:10
  • I do understand the digits for permissions. But, in which group would I put my git-user. I know that git-group is just an example. But would I not have to put the git-user in a group which already has sudo permissions? – thesublimeobject Mar 15 '14 at 01:24
  • No, they don't need to have sudo permissions - just as long as they belong to the group that owns the filesystem - and as long as the group has the right permissions. – rm-vanda Mar 15 '14 at 01:28
  • That makes sense. I'm getting this now: remote: error: insufficient permission for adding an object to repository database ./objects – thesublimeobject Mar 15 '14 at 01:41
  • Also, when I tried using the first command I got this: changing ownership of `/path/to/fcgi-bin/php5.fcgi': Operation not permitted – thesublimeobject Mar 15 '14 at 01:43
  • Even as sudo? That's an Immutable flag -- use this with careful understanding: `sudo -i ; chattr -i /path/to/fcgi-bin/php5.fcgi ; sudo chown [that command]; chattr +i /path/to/fcgi-bin/php5.fcgi ; ` – rm-vanda Mar 15 '14 at 02:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/49784/discussion-between-rm-vanda-and-thesublimeobject) – rm-vanda Mar 15 '14 at 02:01
  • Your last command worked, but I'm still getting that same new git error from a few places above. I am going to try and reset things and go back through some of these commands to see if I can repair things. Thanks a lot for your help. – thesublimeobject Mar 15 '14 at 02:07

1 Answers1

3

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 -

rm-vanda
  • 3,122
  • 3
  • 23
  • 34
  • For anyone interested, the above helped a lot, as did this thread: http://stackoverflow.com/questions/6448242/git-push-error-insufficient-permission-for-adding-an-object-to-repository-datab – thesublimeobject Mar 15 '14 at 02:36
  • What do you mean by git-group here? I'm having this issue, and I'm the only one using my repo (so there's no group as far as I know). – astromax Jan 23 '15 at 15:42
  • There's always a group - and it isn't a "git-group" - it deals with unix file permission groups - so, if you're the only one working on it, the group you'll want to have on your remote repo is 'yourusername' - the instructions above ought to help you - – rm-vanda Jan 23 '15 at 15:56