Tuesday, April 19, 2016

Setting up an internal git server

This is a blogpost to explain how you set up an internal git server on an Ubuntu server the quick and dirty way for a small team.

Setting up the server
Setting up the users
The first thing is to set up all the users. This is done with useradd. In our example our user is named bob

sudo useradd -d /home/bob -s /bin/bash bob

In my case the users already existed. If they do not exist you still need to provide each user with a password using passwd.

sudo passwd bob

Setting up the group who can read and write to the repository server
To make management simple we are going to group all our users in a group and then manage the access on a group level.

sudo addgroup git_users

Adding the users to a group
Next we need to add the users to the group git_users.

sudo usermod -a -G git_users bob

Creating the folder structure
Next we are going to create our repositories.

cd /
sudo mkdir -p /export/git/

Creation of the actual repositories will be done later in the setup.

Setting the ownership
The ownership is still set to root who is configuring the server so we still need to set it to the git_users group so that the users have access.

sudo chgrp git_users /export/git

Set read-write permissions and a sticky bit
Our git_users group needs read and write permissions so they can get to the repositories and write to them. We will use a sticky bit to make sure all objects underneath inherit all the read-write permissions.

sudo chmod g+rws /export/git

Set up our first repository
Our first repository we set up is to manage Powershell scripts.

sudo mkdir /export/git/powershell

To check if our inheritance was correct you can do

ls -la /export/git/powershell

You should see the group have read, write and a sticky bit.

Initializing our repositories
The final step on the server is to initialize the git repository. We use for this two options. The first option is to indicate it is a new repository and is named bare. The second option we use is called shared to indicate it is shared by the whole group.

cd /export/git/powershell
sudo git init --shared --bare

Everything is ready to be used the next step is to use the repositories.

In my next blogpost I will explain how to use Git GUI on Windows system.

No comments: