Skip to content

Setup your own git server using gitolite on ubuntu

If you are a developer and want to have a git server with ability to add users push/pull access you might consider something like a github. But why pay for hosting your private projects if you can use your host in the exactly same way? So let’s try to achieve this on an ubuntu server machine.

After a short search I found gitolite, it looks promising.
Let’s start.

1. Let’s install gitolite

cd $HOME
git clone git:// gitolite-source
cd gitolite-source
sudo mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
sudo src/gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks

2. Generate your ssh public key for YOUR machine which you are using to connect to the server. Skip this step in case you already have it. You may use this command with defaults answers and empty passphrase.

ssh-keygen -t rsa

3. Copy your LOCAL machine ssh public key to the server. This command will copy the key to your home directory on remote machine.

scp /home//.ssh/ username@

4. On REMOTE machine copy the key to tmp directory like this

cp /tmp/.pub

5. Create git user which will host our repos.

sudo adduser git

6. Login into git user account using password you just gave it

su - git

7. Now run the gitolite setup. It will open config file into vi editor allowing you to edit some values before you setup. I left all the values as is and just quit the editor.

gl-setup /tmp/.pub

8. After setup is completed you have to clone the gitolite-admin repo to your local machine. It will be used for adminstration purposes. The command below depends on your server ssh config. In my case server allows only public key login for certain user. So I had to add git user to AllowUsers line in /etc/ssh/sshd_config.

git clone ssh://

9. At this point we can start creating repos and adding users. I won’t dive in a lot of detail here, I will just do some basic stuff.
Let’s add a repo. Open conf/gitolite.conf in the gitolite-admin dir you cloned to your local machine. You will see two default repos there, just copy one of them like this:

repo    test-repo
RW+     =   test-user

This will create a repo named test-repo and adds read-write access permissions to user identified by test-user public key.

10. Let’s add that key. Obtain it from the user you wish to give access and and rename it to Put the key into keydir directory.

11. Let’s commit our changes to the server for them to take effect.

git add .
git commit -m "created test-repo, added RW+ to test-server user"
git push origin master

12. Now user can do the following in an existing git repo. 12345 is your ssh custom port.

git remote add origin ssh://
git push origin master

Now you can simply create new repos and add users to it. Please do read gitolite documentation to discover its power.

That’s it! Goodbye github! :)