The Old Blog Archive, 2005-2009

Installing gitosis on Mac OS X

Garry Dolley’s guide to gitosis installation is excellent and to the point. For those who don’t know, gitosis is a nifty tool that helps you host git repositories via one shared SSH account. gitosis manages access control for you, so you no longer need to rely on the capricious UNIX permission/group settings which is the major headache for hosting your own git repository using ssh://.

Garry’s guide is written mainly for Linux users. For Mac OS X developers, there are a few minor things to take care of, and a few others to skip. For example, /usr/local/bin is not the default path on OS X. On the other hand, you don’t need to install Python. Creating user account is a bit different too.

So here’s a short step-by-step instruction on how to setup gitosis on Mac OS X:

  1. I assume you already have git installed. If you don’t get the latest git for Mac OS X. The quickest way is to get the binary package prepared by Tim Charper and gcheshire. Get it here. Consider getting gitx too.
  2. Find a working directory you like on the target server, then check out gitosis:

    git clone git://eagain.net/gitosis.git

  3. Install it (you need to sudo):

    sudo python setup.py install

  4. Now, create a new user from System Preferences > Accounts. Add a standard user will do. There’s no need to make it an admin account. Let’s call it “git”.
  5. Login with the just created user account. Create .bashrc, fill in the line below:

    PATH=/usr/local/bin:/usr/local/git/bin:$PATH

    This is because on Mac OS X, /usr/local/bin is not in the system’s default exported path setting. We need path access to the directories above.

  6. Now, assuming you’ll be the first user and the admin, you want to use your own public SSH key to access the shared account (that’s the whole point–more on this later). Get your id_rsa.pub onto the target server, or generate using ssh-keygen -t rsa on your local machine. If you don’t know what I’m talking about, read some tutorial on SSH authentication. A quick guide like this is a good start. Be sure you already know that before you move on–this is the crucial part of using gitosis.
  7. After you get your id_rsa.pub onto the target server, login to the server with an account with sudo access (which you don’t with the standard user account we just created above). Then do:
    sudo -H -u git gitosis-init < [path of your id_rsa.pub]

  8. Now login with the standard user account “git”. In your home directory there is already a repositories/ directory, in which you’ll find gitosis-admin.git
  9. Make sure the post-update hook is executable. Do this:

    chmod 755 ~/repositories/gitosis-admin.git/hooks/post-update

From this point on, read Garry’s guide to understand how to manage the admin repository. This is where gitosis is brilliant–you also use git to fetch and update the admin settings! Once you have finish creating your first gitosis-managed repository, the rest is easy. In fact, in our cases, we simply just moved all our bare repositories to under the standard user account’s repositories/ directory. We updated the gitosis config and we got it up and running well.

3 Responses to “Installing gitosis on Mac OS X”

  1. on 14 Jul 2009 at 3:29 amTiago

    It worked like a charm.

    Don’t forget to activate ‘Remote Login’ (System Preferences > Sharing) to activate SSH login.

  2. on 19 Jul 2009 at 5:57 pmShay

    Thanks for the write up, however, I’m getting stuck on step 6. Cannot seem to find gitosis-init

    sudo: gitosis-init: command not found

    Am I missing a step or is something not in my path?
    (PATH=/opt/local/bin:/opt/local/sbin::/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin)

    I’m trying to set this up on my MacPro so that my MacBookPro can use it as the server.

    Any help would be really appreciated.

    Thanks
    Shay

  3. on 19 Jul 2009 at 6:47 pmShay

    Never mind, I put in the full path to gitosis-init (/opt/local/Library/Frameworks/Python.framework/Versions/2.4/bin) and it worked.

    Thanks again for the write up.

    Shay