How to grant read/write to specific user in any existent or future subdirectory of a given directory?
create a group myrepousers
for example, and add your git users to that group.
Then change the group of everything under /path/to/git/myrepo to myrepousers:
chown -R .myrepousers /path/to/git/myrepo
Then fix the permissions:
chmod -R g+w /path/to/git/myrepo
find /path/to/git/myrepo -type d -exec chmod -R {} g+s \;
Should be all set.
Actually that was the wrong approach. After additionnal researches, I found out that in my case I have to user git's buildin features to handle filesystem's right in the repository.
It's basically done with the shared
option of git init
, which can have (among other) the following values:
group
: initialize the repository so that files and directories have user and group write access, and everybody else has read access0660
: same but without read access for the others.
The newly created directories and files automatically have the right permissions. You can also use git init
on an existing repository to reconfigure it without loosing it's content.
So in the end what I had to do:
- Create a group
mygitrepo
- Add users to it
- chmod -R the git repository to
root:mygitrepo
And now every users of the group can pull / push, and nobody else can, and that without messing with the file system rights.
git init --bare --shared=0660
http://www.kernel.org/pub/software/scm/git/docs/git-init.html for more information.
If ACLs are supported, you can do it with default ACLs. Beware that it's easy to forget about those as they don't show up when you do an ls -l
.
find /path/to/git/myrepo -type d -exec setfacl -m d:u:john:rwx {} +
But, I suspect you may want to do something a bit more organised. Deploying gitolite may provide a better solution.