How to Set Up A Gitolite Git Server – A Ten-Minute Tutorial

I ever introduced seting up git server using SSH or gitosis. However, gitolite is the way to go for managing git servers if you want an lightweight authentication layer. gitolite provides many very usefull features which can control each user’s right on each branch. I set up one gitolite git server and am very happy with it. In this post, let’s look at how to set up one gitolite git server. I aim to provide a ten-minute tutorial, and hence, will make the process straightforward, just to the point and as automatic as possible: 1 variable setting, 2 commands with twice asking root password are all steps needed.

Assumptions

I make some assumptions about the git server and your workstation. This should be quite common for many readers. If your environment is not like this, you need to customize the later process by yourself. Both the server and the workstation run Linux, of course. I tested on Fedora 12 and Fedora 19. The method here has minimal requirement about the Linux environment.

About your git server

  • Uses default ssh port (22).
  • With git installed.
  • Has Internet connection for cloning from github.
  • You have the root password to login as root.

root account is needed to create the git user on the git server. If you do not have root, you can customize the following commands by deleting the step for creating the git user. Hence, after a little bit customization, this works on any server that provides ssh, git and Internet connection, such as some shared hosting with ssh enabled.

About your workstation

  • You account already has a private/public key pair. If not, you can generate one by ssh-keygen.
  • You are using bash and you have git, ssh and scp installed on the workstation.

Set up the gitolite git server

Now, let’s start to set the gitolite git server. The following steps is done in one terminal on your workstation.

Collect the information

First, let’s collect some information about the git server and your workstation:

  • Your git server address ($GIT_SERVER).
  • The user ($GIT_USER, usually git) on the git server for storing repositories.
  • The username ($ADMIN, you can use just your login username on your workstation) that you want to use as the administrator.
  • Your public key ($ADMIN_KEY, usually ~/.ssh/id_rsa.pub) for the git repository management.

Usually, you only need to change the $GIT_SERVER in the following commands. Run thee commands:

GIT_SERVER=example.com
GIT_USER=git
ADMIN=$USER
ADMIN_KEY=$HOME/.ssh/id_rsa.pub

Copy your public key to the git server

You will need to input the root’s password.

scp $ADMIN_KEY root@$GIT_SERVER:/tmp/$ADMIN.pub
ssh root@$GIT_SERVER chmod 777 /tmp/$ADMIN.pub

Set up the gitolite environment on the git server

You will need to input the root’s password.

ssh root@$GIT_SERVER "adduser $GIT_USER; su $GIT_USER -c \
\"wget https://raw.githubusercontent.com/zma/usefulscripts/master/script/install-gitolite.sh -O /tmp/install-gitolite.sh && sh /tmp/install-gitolite.sh /tmp/$ADMIN.pub\""

This command ssh to the git server as root and does the follows. First, as root, create the user for hosting git. Then, as the git user, clone the gitolite from github, install it to ~/bin/ and set up the gitolite.

If everything goes well, you will see output as follows

--2015-06-03 14:26:03--  https://raw.githubusercontent.com/zma/usefulscripts/master/script/install-gitolite.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 103.245.222.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|103.245.222.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 448 [text/plain]
Saving to: ‘/tmp/install-gitolite.sh’

     0K                                                       100%  109M=0s

2015-06-03 14:26:03 (109 MB/s) - ‘/tmp/install-gitolite.sh’ saved [448/448]

Cloning into 'gitolite'...
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
Initialized empty Git repository in /home/git/repositories/testing.git/

And the gitolite git server is set up successfully.

Test the gitolite git server

You can test the gitolite git server with the default testing repository provided by gitolite:

git clone $GIT_USER@$GIT_SERVER:testing

You can edit, commit and push in the testing repository. If you are not familiar with git, you can check https://www.systutorials.com/howto-for-new-git-user/ for some help.

Managing the gitolite git server

Management of the gitolite git server is through the gitolite-admin repository, which is similar to managing gitosis git servers. You can clone the gitolite-admin repository:

git clone $GIT_USER@$GIT_SERVER:gitolite-admin

An example task

To give you a brief understanding of how to manage the repositories of the gitolite git server, let’s do one task: create a new repository example-repo, add a new user alice (public key: alice.pub) and give alice read/write/delete access to the repository example-repo.

The commands to do this (replace /path/to/alice.pub with the actual address) are as follows.

cd gitolite-admin
cp /path/to/alice.pub to keydir/
echo "repo example-repo
    RW+     =   alice
" >> conf/gitolite.conf

git add keydir/alice.pub
git commit -a -m 'add alice; add example-repo'; git push

The new repository is created for alice. You can print out the repository address:

echo "$GIT_USER@$GIT_SERVER:example-repo"

For more controls and rules supported by gitolite, you can check the gitolite manual.

What’s next step? The first step after setting up a git server is usually setting up email notifications: https://www.systutorials.com/setting-up-git-commit-email-notification/.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

6 comments:

  1. Gitolite seems to be a lightweight Git server manage tool. It looks good. I am using GitLab, which look like a private GitHub.

    1. GitLab is a piece of great software providing a Web interface for git repository management. Right, gitolite is only a authorization layer for git, which is strictly not a git hosting environment.

  2. How to use Gitolite with port forwarding. For example, I use a server that is a local network and use port forwarding to login.

  3. Hello, I have been using this setup for installs on Centos 7. Without any problm.
    Now I wanted to do the same on a new Rocky 8 server.
    All goes well until I clone the testing(or gitolite-admin) repo. At this point I get a prompt asking for password.
    git version 1.8 ( Centos7)
    git version 2.3 (Rocky 8)
    Is there a way to make that working in Rocky 8 ?
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *