Gitosis and Gitweb – Part 1 – Setup

I’ve had a number of people ask me where they should host their Git repositories. Of course, my default question back is, “Can the code be public or does it need to be private?”. Usually they say, “public”. Therefore, my repsonse is Github.com. If they say, “private” I still say Github.  If they don’t “trust” Github, which they should – click the link, then my response is Gitosis and Gitweb. This is by no means the only solution. I’m aware of other ones like Gitorious. I’ve never used Gitorious.

Back to Gitosis. My personal Gitosis server is a slice at Slicehost.com. You can use an Ubuntu server at home as long as you have remote access. I’ve personally only used Gitosis with an Ubuntu slice, so I don’t know if there are any quirks with other Linux distributions. After setting up a slice (after following the instructions here and here) I am ready to go.

Notice: This post is a combination of scie.nti.st’s gitosis post and Scott Chacon’s Pro Git gitosis section. They are my de facto references. Maybe my own will be now. :)

“Enough talk. Let’s fight” ~Po, Kung Fu Panda

Intall Git

After logging into your box, let’s install Git (if not already installed):

Press enter or type ‘Y’ and press enter and git will be installed. Type the following to confirm:

and you’ll see something like:

Intall python-setuptools

Also install the python-setuptools because we’ll need them (gitosis is written in python):

Press enter or type ‘Y’ and press enter and python-setuptools will be installed.

Download Gitosis

We need to clone the gitosis source locally to install it:

Install Gitosis

Now let’s install it:

Gist. Gitosis is now installed. Next steps are to create git user and handle a file permission on a git hook.

Create Git User

You’ll see something like the following if it is successful

Use local, public ssh key

You need to initially use your public ssh key (id_rsa.pub). If you have one, it will be at $HOME/.ssh/id_rsa.pub and if you have never generated one, you can do so by running the following command (accept the default location and you don’t need to enter a passphrase when prompted):

Now you need to upload it to the server/slice. I usually use the scp (secure copy command):

This will upload the local id_rsa.pub file to the /tmp/ folder on the server. Why there? So that the git user can use it. How is that possible? The folder has permissions of 777 (drwxrwxrwt) meaning everyone has read and write access to it.

Sidenote: SSH Port

If you have your sshd daemon running on a different port other than 22 (which is the default, but I highly suggest changing), then you need to use scp like this:

I believe the “-P” option must be capitalized.

Initialize gitosis-admin repository

On the server, issue the following command to set your public ssh key as the first authorized key of a new gitosis-admin repository:

You will see something like the following:

This means it was successful.

Take note: If you put your id_rsa.pub file in a different location you need to use that instead of /tmp/id_rsa.pub

Change Permissions on post-update hook

You have to set the permissions on the post-update git hook of the gitosis-admin repository so that gitosis-admin can add new repository structures when they are added/removed to/from the gitosis.conf file.

Note: First round of this post, I didn’t make this change. When I added a new project, it failed because this hook didn’t have the right permissions.

Clone gitosis-admin repository

Now we’re going to use Git to administrate this gitosis instance. I think that is pretty ingenius. Let’s clone the gitosis-admin repository locally:

We are now in the gitosis-admin repository folder locally

Two most common errors

FIRST ONE:

it is because you have used a port for SSH other than port 22 (the default). To fix this, you need to edit your .ssh/config file and add the following:

Of course, you need to put in your server hostname and port number (i.e., mydomain.com and 12345)

SECOND ONE:

This has usually hit me because I locked down my /etc/ssh/sshd_config file to only allow in certain users or groups. I have to change the AllowUsers line in my file from:

to

Once I restart the ssh daemon:

Now the git user has access to reach my server/slice via ssh.

The local gitosis-admin repository

You now have a local clone of the gitosis-admin repository. The contents are only a conf file and key directory:

 

Note: before anyone asks, the (master) notation in my prompt is usage of the __git_ps1

Next Part: Add Projects and Contributors

 

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jason Meridth

Continuously learning software developer trying to not let best be the enemy of better
This entry was posted in git, gitosis. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Comments are closed.