Installing a gitolite server
While the above is sufficient to create, clone and edit repositories, users wanting to install git on a server will most likely want to have git work like a more traditional source control management server, with multiple users and access rights management. The suggested solution is to install gitolite with the following command:
sudo apt install gitolite
Configuration of the gitolite server is a little different that most other servers on Unix-like systems. Instead of the traditional configuration files in /etc/, gitolite stores its configuration in a git repository. The first step to configuring a new installation is therefore to allow access to the configuration repository.
First of all, let’s create a user for gitolite to be accessed as.
sudo adduser --system --shell /bin/bash --group --disabled-password --home /home/git git
Now we want to let gitolite know about the repository administrator’s public SSH key. This assumes that the current user is the repository administrator. If you have not yet configured an SSH key, refer to ???
cp ~/.ssh/id_rsa.pub /tmp/$(whoami).pub
Let’s switch to the git user and import the administrator’s key into gitolite.
sudo su - git
Gitolite will allow you to make initial changes to its configuration file during the setup process. You can now clone and modify the gitolite configuration repository from your administrator user (the user whose public SSH key you imported). Switch back to that user, then clone the configuration repository:
git clone git@$IP_ADDRESS:gitolite-admin.git
The gitolite-admin contains two subdirectories, “conf” and “keydir”. The configuration files are in the conf dir, and the keydir directory contains the list of user’s public SSH keys.
Managing gitolite users and repositories
Adding new users to gitolite is simple: just obtain their public SSH key and add it to the keydir directory as $DESIRED_USER_NAME.pub. Note that the gitolite usernames don’t have to match the system usernames - they are only used in the gitolite configuration file to manage access control. Similarly, users are deleted by deleting their public key file. After each change, do not forget to commit the changes to git, and push the changes back to the server with
git commit -a
git push origin master
Repositories are managed by editing the conf/gitolite.conf file. The syntax is space separated, and simply specifies the list of repositories followed by some access rules. The following is a default example
RW+ = admin
R = alice
RW+ = alice
RW = bob
R = denise
Using your server
To use the newly created server, users have to have the gitolite admin import their public key into the gitolite configuration repository, they can then access any project they have access to with the following command:
git clone git@$SERVER_IP:$PROJECT_NAME.git
Or add the server’s project as a remote for an existing git repository:
git remote add gitolite git@$SERVER_IP:$PROJECT_NAME.git