How to grant read/write to specific user in any existent or future subdirectory of a given directory

gitpermissions

I host my own git repository on a VPS. Let's say my user is john.

I'm using the ssh protocol to access my git repository, so my url is something like ssh://john@myserver.com/path/to/git/myrepo/.

Root is the owner of everything that's under /path/to/git

I'm attempting to give read/write access to john to everything which is under /path/to/git/myrepo

I've tried both chmod and setfacl to control access, but both fail the same way: they apply rights recursively (with the right options) to all the current existing subdirectories of /path/to/git/myrepo, but as soon as a new directory is created, my user can not write in the new directory.

I know that there are hooks in git that would allow me to reapply the rights after each commit, but I'm starting to think that I'm going the wrong way because this seems too complicated for a very basic purpose.

Q: How should I set up my right to give rw access to john to anything under /path/to/git/myrepo and make it resilient to tree structure change?

Q2: If I should take a step back change the general approach, please tell me.

Edit: The question was answered as is, but that was the wrong question. The right question would have been "How to configure a bare git repository on the server for use with ssh access?". See my own answer.

Best Answer

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.

Related Question