Wednesday Aug 07

Key Concepts

Hosting Git Repositories on Ubuntu

Sébastien Dante Ursini
Monday, 25 March 2013 18:03
Written by Sébastien Dante Ursini
AddThis Social Bookmark Button

Gitolite repository on ubuntu server 

Setting up a Git Server on Ubuntu

Github is a wonderful service,site and community of developers. But sometimes you don't want to make your work public. To keep your work private you can pay for private repositories or install your private Git repository on your server.

Gitolite allows you to setup git hosting on a central server, with very fine-grained access control and many (many!) more powerful features.

In this tutorial i will show you detailed instructions of how to setup Git on Ubuntu server

Generate an authentication key for ssh

Open your client machine open a shell prompt and execute the following command to generate an authentication key for ssh :

Create ssh key for gitolite installation on ubuntu

$ ssh-keygen -t rsa

You should get the below result and input the SSH passphrase. If you keep the original location you should find your newly created ssh key at /Users/<user name>/.ssh/id_rsa 

Note: it is possible to just press the enter key when prompted for a passphrase, which will make a key with no passphrase. This is a Bad Idea for an identity key, so don't do it!

Create ssh key for gitolite installation on ubuntu

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/java-tutorial/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/java-tutorial/.ssh/id_rsa.
Your public key has been saved in /Users/java-tutorial/.ssh/id_rsa.
The key fingerprint is:
05:b9:9b:f8:85:46:2d:c8:48:58:f9:3d:8b:2d:1c:93 java-tutorial@java-tutorial.local
The key's randomart image is:
+--[ RSA 2048]----+
|   o..  ..       |
|  . o   ..       |
|   . + + o.      |
|    . E *..      |
|     . BSB       |
|      = B .      |
|       + .       |
|        .        |
|                 |

Upload your key on your Ubuntu server

We will transfer the key located in the file to your Ubuntu host by using scp but you can use ftp,rsync or any other method. 

transfer ssh key for gitolite on our ubuntu server

scp ~/.ssh/

Our ssh key is now present on our Ubuntu server in the following location /tmp/

Open an ssh session and create a Gitolite user

if your user is named user and our Ubuntu domain is named 

Create ssh key for gitolite installation on ubuntu


We are connected on our Ubuntu server. Let's create a Gitolite user with the useradd command

Create gitolite user on ubuntu

sudo useradd -d /home/gitolite -m gitolite
sudo passwd gitolite

With the first useradd we create a a new user called gitolite. The -d option is used to set the home directory for the user. The -m option will force useradd to create the home directory.

Additional options :

useradd command options


Create the user as a system account
--shell The name of user's login shell

Install Gitolite package

The necessary packages are available in Ubuntu's standard repositories. To install those packages you can type the following shell command :

Create ssh key for gitolite installation on ubuntu

$ apt-get install gitolite

Execute the Gitolite setup script

Switch to the gitolite user and execute the Gitolite setup command. The setup command called gl-setup expects a pubkey filename the first time it is run and will complain if you don't supply it. It is the ssh key we have created during the first steps.

On subsequent runs it is optional. You need to supply it if you want to change the admin's pubkey without all the steps that gl-admin-push requires and we will not cover.

Create ssh key for gitolite installation on ubuntu

$ su - gitolite
$ cd 
$ gl-setup /tmp/

it creates the following files :

  • .gitolite.rc
  • conf/gitolite.conf 
  • keydir/

Create ssh key for gitolite installation on ubuntu

creating gitolite-admin...
Initialized empty Git repository in /home/gitolite/repositories/gitolite-admin.git/
creating testing...
Initialized empty Git repository in /home/gitolite/repositories/testing.git/
[master (root-commit) 2777944] start
 2 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 conf/gitolite.conf
 create mode 100644 keydir/

The rest of the process will take place on the client side. Thanks to Git.

Create you own repository

Back on our client machine using our regular account, we can now clone the gitolite-admin repository to adapt the repository configuration to our needs. 

Create ssh key for gitolite installation on ubuntu

$ git clone

So we have a copy of the administration configuration on our client machine. We will go in the gitolite-admin reposiroty and create our repository.

Create ssh key for gitolite installation on ubuntu

$ cd gitolite-admin
$ vi conf/gitolite.conf

The gitolite-conf should look like 

repo    gitolite-admin
        RW+     =   id_rsa

repo    testing
        RW+     =   @all

To create our own repository called devzone. You can add the following snippet

repo    devzone
        RW+     =   @all

To make it available we need to commit and flush

Create ssh key for gitolite installation on ubuntu

git commit -a -m "new 'devzone' repository"
git flush

Congratulations you have a new repository called devzone hosted on your Ubuntu server.

If you have any remark or questions feel free to put a comment.

If you enjoyed this tutorial and want to promote it don't hesitate to click on

Tags: user, create, ubuntu, repository, gitolite
Sébastien Dante Ursini

Sébastien Dante Ursini

Java/Finance Specialist 
17 Years of experience in Java
22 Year in Banking/Finance
Based in Geneva/Switzerland

Java Tutorial on Facebook