Installing git and gitosis on an Ubuntu server

Discover a simple way to manage git repositories, with tight access control. This quick setup guide runs through the install of git and gitosis on an Ubuntu server.


Gitosis provides a easier way to manage git repositories, provide access to them over SSH, with tight access control but without needing shell accounts. Following guide is copied from Ubuntu’s Community Documentation Git install guide.

Install git and gitosis:

sudo apt-get install git-core gitosis

Copy the public ssh key from your local machine to the server (i.e. the file ending in .pub):

scp ~/.ssh/ <user>@<host>:~

Initialize gitosis using your key:

sudo -H -u gitosis gitosis-init < ~/

From this point on, you don’t need to be on your server. All configuration takes place locally and you push the changes to your server when you’re ready for them to take effect.

You can now checkout the gitosis-admin branch on your local machine:

git clone gitosis@<host>:gitosis-admin.git

Creating new repositories

To create a new repo, we just authorise writing to it and push. To do so, add this to gitosis.conf:

[group dev]
members = ben
writable = newproject

Your “members” line will hold your key filename (without the .pub extension) that is in keydir/. This defines a new group called “dev”, which is an arbitrary string. “ben” is a member of the dev group and will have write access to the “newproject” git repository.

Save this addition to gitosis.conf, commit and push it:

git commit -a -m "Allow ben write access to newproject"
git push

Committing to the first project

mkdir newproject
cd newproject
git init
touch README.txt
git add .
git commit -a -m "Initial import"
git remote add origin
git push origin master

Or, if you already have a local git project you can just configure the origin and push:

git remote add origin
git push origin master

Adding new users

Simply add the user’s SSH public key (.pub extension) to the keydir in the gitosis-admin git repository. Then add the key filename, minus the .pub extension, to the “members” list of the group you want them to be included, in the gitosis.conf file.

[group dev]
members = ben newuser
writable = newproject

Then commit the changes:

git commit -a -m "Add newuser to dev group"
git push

Non-standard SSH port

If you run SSH on a non-standard port on your server (recommended), don’t use the syntax, it won’t work. Instead, put the port number in your ~/.ssh/config file:

Port 1234

Git GUI clients (for Mac)

Now you have a git server and can create as many repositories as you like, you’re probably keen to start using git. The following three Mac apps are available to provide a user-friendly graphical interface.