Git and Gitosis on Debian Squeeze

This is an archive of blog post I wrote during my first venture (beginning of 8thcolor).

PreliminariesπŸ”—

We've started to prototype some of our ideas those last weeks. Currently, we're working on 3 projects. For one, we have 2 branches. Today, it exists wonderful tools to manage collaboration and revision of source code. Even when I'm alone in a software development project, I use one. It is about time to set up one for enkio.

The purpose of the current post is not to deal with the trollable question "which RCS is the best". Maybe I'll share later about that, but not now. We have chosen Git because it is used by the RoR and Django communities and dedicated hosting solutions, and we want make our opinion by ourselves.

This howto concerns the installation of Git and Gitosis. The last one is a simple manager of repository access using SSH key and not needing shell accounts. Before starting, here are some conventions I'll use for prompt symbols:

> = remote
$ = local

InstallationπŸ”—

As usual, update your package db:

> aptitude update

Install git and gitosis

> aptitude install git-core gitosis

The Debian package has created a gitosis sys user and its home directory is at /srv/gitosis.

Init GitosisπŸ”—

Now, you need to setup gitosis and the administration access. To do that you need a SSH public key that I simply name id.pub here. First of all, copy this key on the server in the /tmp directory:

$ scp id.pub your.server.com:/tmp

You can now setup gitosis:

> su gitosis
> cd
> gitosis-init < /tmp/id.pub
Initialized empty Git repository in /srv/gitosis/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /srv/gitosis/repositories/gitosis-admin.git

This creates the repository gitosis-admin, setting up gitosis. But to effectively set up gitosis you have to clone it locally, in order to work on its setup file gitosis.conf and add new SSH public keys for other users.

Retrieve gitosis-admin locallyπŸ”—

But before don't forget to correctly setup your SSH by adding at least the following in your ~/.ssh/config file:

$ cat << EOF > ~/.ssh/config
Host your.server.com
	IdentityFile ~/.ssh/id
EOF

Now you can clone the gitosis-admin repository:

$ git clone gitosis@your.server.com:gitosis-admin.git
Cloning into gitosis-admin...
Enter passphrase for key '/home/you/.ssh/id':
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.

In the directory gitosis-admin, you'll find the gitosis.conf file and the directory keydir where you have to put git user SSH public keys.

$ ls gitosis-admin
gitosis.conf  keydir
$ ls gitosis-admin/keydir
id.pub

Let's take a look into gitosis.conf file:

$ cd gitosis-admin
$ cat gitosis.conf
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = id

A group gitosis-admin is already set up. It gives write access to the gitosis-admin repository and there is a member: id. id is the user name associated to the SSH public key defined inside the file id.pub.

Setup access to the new repositoryπŸ”—

To illustrate how to use and setup gitosis, I'll create a repository and give write access to another user. First of all, I have to set up the access:

$ cat << EOF >> gitosis.conf
[group myteam]
writable = myproject
members = id another
EOF

By adding those lines, all members of group myteam have been given write access to myproject. And members of this group are id and another. I do not forget to add a SSH public key for another user:

$ cp ~/another.pub keydir/
$ git add gitosis.conf keydir/another.pub
$ git commit -m "give write access to group myteam on project myproject"
$ git push

And it's done.

Create the new repositoryπŸ”—

Then, I can create a blank repository myproject:

$ cd ..
$ git clone gitosis@your.server.com:myproject.git
Cloning into myproject...
Enter passphrase for key '/home/id/.ssh/id':
Initialized empty Git repository in /srv/gitosis/repositories/myproject.git/
warning: You appear to have cloned an empty repository.

VoilΓ !

ReferencesπŸ”—


If you have any comment, question, or feedback, please share them with me.


Atom feed icon Subscribe to the blog!