Installing Git and gitosis on Ubuntu

I’m switching all my personal projects to git from Subversion. To that end, I’ve set up a remote git repository on my Linode.com VPS running Ubuntu. Here’s how to do it:

First, install git on the remote server:

sudo apt-get install git-core

Then, following instructions on scie.nti.st, we grab the gitosis code (still remote):

cd ~/src
git clone git://eagain.net/gitosis.git

Then:

cd gitosis
sudo apt-get install python-setuptools
sudo python setup.py install           # I had to do sudo here
sudo apt-get install python-setuptools # I also needed these tools

Next, create a git user to own the repositories:

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git

I copied my public ssh key from my workstation to the remote server at /tmp/id_rsa.pub, (tmp avoids perms issues with git) then run

sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

And that’s the end of the server-side setup! On the local machine, we check out the files that are needed to control the server.

If you run SSH on a nonstandard port: edit ~/.ssh/config and put this inside:

Host www.example.com
    Port 32767

Then you can do:

git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
cd gitosis-admin

The gitosis-admin is the directory where you administer gitosis. From this point on, you don’t need to be on your server. All configuration takes place locally and you push the changes to your server when you’re ready for them to take effect.

  • Pingback: Redmine with GIT Repository Setup on Ubuntu « Ryan Alberts

  • Paz

    Just tried 3 other tutorials that were not clear on copying my public key from client to server and wasted 30mins. Yours got me there in 2 mins. thanks.

  • Jdoerring

    I posed this on the scie.nti.st article but they have a comment list a mile long so here it is again.

    I'd like to add on one thing that I ran into when installing Git and Gitosis on my Ubuntu 10.10 server which I installed with encrypted home directories.

    When I was configuring my server for SSH, I changed my sshd_config to include this entry:
    AuthorizedKeysFile /etc/.ssh/%u/authorized_keys

    From this you can see that I created a /etc/.ssh directory and a sub directory for each user containing the file authorized_keys. Also, I made the user the owner of their respective folder.

    Gitosis uses a post-update hook to update the git user's authorized_keys file to include each of the public keys from the gitosis-admin/keydir. The problem was that the default location that gitosis expected the authorized_keys file to be in was /home/git/.ssh/ but I moved it to /etc/.ssh/git. To remedy this I had to add the following to gitosis.conf:
    [gitosis]
    ssh-authorized-keys-path = /etc/.ssh/git/authorized_keys

    It took me quite a bit of messing around to figure this all out, I hope it will save someone else the pain.

  • http://tenach.net tenach

    I am getting a traceback error and am not sure what to do with it: http://tlms.pastebin.com/pQi0v… What would your suggestions be? I have triple-checked to make sure I am following everything properly.

    Thank you much for your help.

  • mrichman

    Issues or questions about Gitosis should be directed here: https://github.com/res0nat0r/g