Shared Git repository over ssh for multiple users

Table of Contents

This tutorial will show you how to set up a shared git repo with multiple accounts over ssh. Only ssh, not gitolite or any other software. This is usefull if you have a small team of people that don't often need access to the repo and don't want something like github or bitbucket. With this you can use existing infrastructure.

I have used this for a sysadmin team which had a few scripts scattered.

Folders and Permissions

First set up a new group for the users of the repository. You can use the groupadd command but I find it easier to edit /etc/group and add a line line this:

gitusers:x:2222:user1,user2,user3,user4

Do note that all the users you add above should have an account on the system. (adduser user/useradd user)

Now create a folder to house the repo's:

mkdir -p /var/git/repository1

Then change the group permissions on that folder:

chgrp gitusers /var/git/repository1
chmod g+ws /var/git/repository1

Repository

We can now create the repository. Navigate to the folder and initialize the repository:

cd /var/git/repository
git init --bare --shared=group

That's it. Now you can clone, pull, push and commit the repo like normal:

git clone git+ssh://user1@gitserver/var/git/repository1

Script

A simple script which makes the above easier. This assuming the group is gitusers and the root path is /var/git/.