FOLLOW ME Twitter Facebook Вконтакте LinkedIn RSS Feed

How to setup a private git repository on Debian using Gitosis

Category: Tips and Tricks
Apr 19, 2012
Konstantin Bulenkov

In this post I’m going to give you step by step instructions of how to setup your own git repository. I’ve got a VDS (Virtual Dedicated Server) running on Debian 6.0.4, but all steps are valid for Ubuntu too.

First of all we should setup all necessary tools including git:

apt-get install git python-setuptools python-dev

After that, get gitosis sources. Official repository git:// stopped working, so use github repository instead:

git clone
cd gitosis
python install

Check that you’ve got sudocommand installed and if it’s not install it.

apt-get install sudo

I didn’t have sudo installed on my VDS so that’s why I care about it.
Ok, then create and add a gitosis user:

sudo adduser --system --shell /bin/sh --gecos 'gitosis user' 
             --group --disabled-password --home /home/git git

Now it’s time to set up a security connection between your local machine and the server. If you already have a private key and you know what is that, just skip the next step. Otherwise, you should generate keys on your local machine.

ssh-keygen -t rsa

If you’re a Windows user, you should find some way to generate security keys. For instance, use PuTTY gen.

Next step is to copy your public key to the server. Copy somehow to the server. For example, using scp command

scp ~/.ssh/ USER@SERVER_NAME:/tmp/

Initiate gitosis:

sudo -H -u git gitosis-init < /tmp/
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/

Go back to your local computer and clone admin’s repository:

git clone git@SERVER_NAME:gitosis-admin.git
cd gitosis-admin

Open and edit gitosis.conf. It should look like:


[group gitosis-admin]
writable = gitosis-admin
members = USER

Copy and paste at the end last 3 lines, rename gitosis-admin to your repository name. So, the config should finally look like:


[group gitosis-admin]
writable = gitosis-admin
members = USER

[group myproject]
writable = myproject
members = USER

Save the config and commit-n-push it

git commit -a -m "Create repository for myproject"
git push

Now create a directory for your project, add files and sync it with remote repository:

mkdir myproject
cd myproject
git init
touch readme.txt
git add .
git commit -a -m "initial"
git remote add origin git@SERVER_NAME:myproject.git
git push origin master

Well done!

Adding users

To add a user to the project myproject ask him to send you his public key. Rename it to or to (it’s better to open pub file and look at the end of it. There you can find a user name). Ok, then copy the public key (say to gitosis-admin/keydir/ folder on you local computer. Add the file to the git:

cd gitosis-admin
cp /tmp/ keydir/
git add keydir/

Allow contributor to access myproject. Edit gitosis.conf:


[group gitosis-admin]
writable = gitosis-admin
members = USER

[group myproject]
writable = myproject
members = USER contributor

Now commit and push everything:

git commit -a -m "Add new contributor to myproject"
git push origin master

That’s all. Please comment/retweet if this post was useful.

Leave a comment