1

So I usually create git hook like this (root only):

git init --bare
nano /home/git-repo/www.example.com.git/hooks//post-receive

Paste this

#!/bin/sh
GIT_WORK_TREE=/home/nginx/domains/www.example.com/public git checkout -f
GIT_WORK_TREE=/home/nginx/domains/www.example.com/public git checkout -f master
GIT_WORK_TREE=/home/nginx/domains/www.example.com/public git clean -f

Then

chmod +x /home/git-repo/www.example.com.git/hooks//post-receive

But now I tried create new user for access git repository and set permission so new user only can access some git repository and what I tried is:

useradd NewUser
groupadd Developer
usermod -G Developer NewUser
chgrp Developer /home/git-repo/www.example.com.git/hooks//post-receive
chmod +x /home/git-repo/www.example.com.git/hooks//post-receive

But when I push I am getting this error:

Counting objects: 1549, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (826/826), done.
fatal: Unable to create temporary file: Permission denied
fatal: sha1 file '<stdout>' write error: Broken pipe
error: failed to push some refs to 'ssh://NewUser@(my.vps.ip.0):(port)/home/git-repo/www.example.com.git'

How to solve my problem? I just need to create git repo with hooks and new user can only access some of my git repository

phd
  • 82,685
  • 13
  • 120
  • 165

1 Answers1

0

If you want to give NewUser access to some repositories that belong to Developer group first you have to change permissions for the repository(ies):

chgrp -R Developer /home/git-repo/www.example.com.git
chmod -R g+w /home/git-repo/www.example.com.git
find /home/git-repo/www.example.com.git -type d -exec chmod g+s '{}' \+

I.e., set group, allow write access to the group, make all existing directories to propagate the group for newly created files and directories.

And then configure git to retain these permissions, that is to create all files with permission -rw-rw-r--:

git config core.sharedRepository group
phd
  • 82,685
  • 13
  • 120
  • 165
  • should I have permission to /home/nginx/domains/www.example.com/public too? I think its permission denied – VanillaRong Jul 24 '17 at 02:12
  • My explanation was only about `www.example.com.git` repo. You can repeat that commands for any repo to which you want to give access to NewUser. – phd Jul 24 '17 at 14:33
  • nope, I mean should I get same permission to folder that I targeted where I need to store file? – VanillaRong Jul 25 '17 at 09:08
  • You have to have write access. If when you "say should **I** get same permissions" you mean "I want to write to a directory that belongs to group Developer but not user NewUser" — then yes, `chgrp g+ws`. – phd Jul 25 '17 at 10:09