OK so maybe it’s time I write something useful.
Gitosis:
- Pros: A fantastic program which simplifies the task of securely hosting git repositories.
- Cons: It doesn’t do read-only unsecured shares
Getting Gitosis
There are gitosis packages for mos major distros but I haven’t had much luck getting them to work, best to get the latest source:
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
Don’t forget to install python setuptools.
Preparing the System
Now you have to set up a user for gitosis to run as. The hosted repos will be stored in this user’s home dir, so choose wisely. On my system I did
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git
Now, every user who interacts with Gitosis will need an SSH key. Check ~/.ssh, if you’ve got id_rsa.pub in there you’re good otherwise generate one by
ssh-keygen -t rsa
Now to initialize a gitosis instance for your created user with your personal user authorised to administer. Copy your public key to /tmp (so you don’t have permission problems later on) then
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
Now comes the sweet bit of Gitosis – administration isn’t actually done on the server, all gitosis hosting configuration is itself hosted by gitosis. On your personal machine then, clone the admin repository
git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
cd gitosis-admin
Now the administration workflow is
- Edit gitosis-admin/gitosis.conf
- Add user’s public keys to gitosis-admin/keydir
-
git add keydir/* -
git commit -a -m 'Describe your changes' -
git push
Creating a new Repo
OK so now you’re set up and authorised for administration, sweet. Let’s set up our first repository. Open gitosis-admin/gitosis.conf and add a section like
[group groupname]
members = usernames
writable = new-repo
Where of course group names should be descriptive, new-repo is the name of, you guessed it, your repository and usernames is a space-separated list of fully qualified usernames allowed to write. That is, “user1@somecomp user2@anothercomp” etc.
Save this and exit. If there are users other than yourself in the list, copy their keys to gitosis-admin/keydir. The keyfile filenames should be the fully qualified username with a .pub extension, eg user1@somecomp.pub.
Add and commit any changes and push them back to the server like
git add keydir/*
git commit -a -m 'Added new-repo with users user1, user2'
git push
And that’s the configuration done. Now you of course need to give the repo content. We’re going to make the repo locally and push it up, so
cd ~/code/my-repo
git init
#make some changes, commit
git remote add origin git@SERVER_HOSTNAME:new-repo.git
git push origin master:refs/heads/master
Note that the push will fail unless you have at least 1 commit on the master branch. Once you’ve done this once, git will remember the local and remote refs so you’ll only need to
git commit [OPTIONS]
git push
And that’s it! There are a fair few config options I’ve left out, like using group names as user names in writable lists, read-only access (but not public access) etc. Check out example.conf in the directory where you originally cloned gitosis for more info.
