Quantcast
Viewing latest article 2
Browse Latest Browse All 6

Set up a simple git server on a Plesk managed webserver

Having an own server is great, because you can have things like your own git server installed. Many use gitosis or similar, for small teams I prefer the standard interface that git provides itself. Plus, we will install GitList, a read-only web interface for your git repos which looks similar to Github.

This is more a list of links with how to achieve this on a Plesk managed Webserver. I commented every link with what I tweaked to make everything work together. I have a VServer running CentOS 6.3, but this will work very similarly on any other linux platform.

Install the latest git from source

Git can be installed using your preferred packet manager, in my case that would be yum.

Beware though, on CentOS the latest git release is already a little old. I therefore compiled it myself using this easy-to-follow guide on the git homepage itself. This was necessary because the latest GitList requires a bleeding-edge git - not a problem, really.

Make it accessible from outside

Being root, add a new user git via SSH and set its password:

$ adduser git
$ passwd git

In git's home directory in /home/git create a new directory called "r" for repositories - I just made it short to reduce typing.

$ mkdir r

What you have to do now is secure the shell access for the git user, so that it can only execute necessary git commands and not do any harm to your repositories.
Therefore, git provides its own shell called git-shell. First, we have to add the shell to the list of available shells. Edit the /etc/shells file with your preferred editor and add the following line:

/usr/bin/git-shell

To enable it for the git user, you need the following command:

$ chsh -s /usr/bin/git-shell git

Now, you have successfully set up your server. Additionally, you can provide passwordless login with key files for selected machines. To do so, read the following guide.

Setting up repos my way

Because the git user doesn't have a usable shell any more, we will have to create new repositories using a different user (in my case it's root, but don't hesitate to create an additional user and give it read/write permissions on the git and r folder). This means, though, that we will have to edit the repository ownership (as it will belong to root and git won't be allowed to read or modify it). To save time, I created a script called addRepo.sh in git's home directory with the following content:

# get name of new repo
echo "File name of the repository: "
read name

# create bare repo
mkdir r/${name}.git
cd r/${name}.git
git --bare init

# set permissions
cd ..
chown -R git:psacln ${name}.git

echo "Repository created."

Now make the script executable ( $ chmod 700 addRepo.sh ) and now you can add repositories by calling $ ./addRepo.sh and providing the relevant information - with the user that you created the script.

Go ahead and create a test repo:

$ ./addRepo.sh
myRepo

Finally: Using your new git server

On your local machine, you can now clone the newly created repository myRepo like this:

$ git clone ssh://git@yourserver.com/~/r/myRepo.git

It will ask you for git's password (unless you've set up the passwordless ssh login), and clone the repo. You can start working. You can push to your server just like you would push to any other git server:

$ git push origin branch

Notes on users

While all your team members will log in using the very same credentials for the git user, you will still be able to distinguish their commits because they all (I assume) have set up their own local user.name variables.

Installing a web frontend

Personally, what I love about GitHub is the web frontend. But on my own server, I don't have one. In another post, I describe how to extend our setup with a read-only web frontend which is pretty similar to what GitHub looks like. Have fun reading.

Hopefully all is working fine for you, if you have any better ways to share, please do so in the comments.

Categories: 

Tags: 


Viewing latest article 2
Browse Latest Browse All 6

Trending Articles