Falling Leaves: the Ardes blog

git hosting with Leopard

May 19th, 2008

Ian White

So you wanna host your own git repos? Got Leopard? Got Git? Read On...

Assumptions: You have git installed.


Create a git server on leopard with gitosis

Download and install gitosis

  mkdir src
  git clone git://eagain.net/gitosis.git
  cd gitosis
  sudo python setup.py install

Create a git user and group on the server

Create a unix user and group for git, using dscl: leopard's directory service cli

1. Find an unused uid and gid

  sudo dscl . list /Users uid
  sudo dscl . list groups gid

(check that, say, 401, is unused in both)

2. Create the git group

  sudo dscl . create groups/git
  sudo dscl . create groups/git gid 401

3. Create the git user

  sudo dscl . create users/git
  sudo dscl . create users/git uid 401
  sudo dscl . create users/git NFSHomeDirectory /Users/git
  sudo dscl . create users/git gid 401
  sudo dscl . create users/git UserShell /bin/bash
  sudo dscl . create users/git Password '*'

4. Create the git home directory (make this location match the end of line 3 above)

  sudo mkdir /Users/git
  sudo chown git /Users/git
  sudo chgrp git /Users/git

Create an ssh key, and copy it to the server

1. If you don't already have one, create an ssh key, on your local machine if it is not the server

  ssh-keygen -t rsa

2. Copy the public key to /tmp on the server

(if your local machine is the server)

  cp ~/.ssh/id_rsa.pub /tmp/my_key.pub

(if the server is different from your local machine)

  scp ~/.ssh/id_rsa.pub your.server.com:/tmp/my_key.pub

Setup gitosis in git user's home directory

1. Initialise gitosis [on the git server]

  sudo -H -u git gitosis-init < /tmp/my_key.pub
(you should see something like this:)
  Initialized empty Git repository in ./
  Reinitialized existing Git repository in ./

2. Make sure git's paths are set to your current ones (where you can see gitosis and git)

  sudo su git  (enter your password)
  echo "export PATH=$PATH" > ~/.bashrc
  exit

Update: drwestco advises that with git 1.6 you should append the following line to the git user's .bash_rc.

export PATH=$(git --exec-path):$PATH

Clone the gitosis repo to your local machine

  git clone git@your.server.com:gitosis-admin.git

If you see something like this, then you're all set

  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.

What next?

Get familiar with gitosis. scie.nti.st has a great writeup for *nix systems, which I used as a reference point. The end of that blog has some general intro to gitosis.

Troubles? Make sure that you can ssh to the server as git (make sure that Leopard's ssh settings allow any user to login, or edit /etc/sshd_config). Otherwise post your troubles here in the comments.

15 Responses to “git hosting with Leopard”

  1. Omarvelous

    Omarvelous Says:

    Lovely tutorial... Got up to the last part, testing it. It works.... but I got an error: ssh: connect to host 192.168.2.123 port 22: Bad file number fatal: The remote end hung up unexpectedly fetch-pack from 'git@192.168.2.123:gitosis-admin.git' failed. 192...123 is my server's internal IP. Any wonder as to why I've gotten that error? Also, how would one go about changing the password? I believe mine is blank at the moment, I believe bak in this step (sudo dscl . create users/git Password '*') would be where I set it. Will try now. Thanks in advanced! Omar
  2. drwestco

    drwestco Says:

    One change needed to get this working on my machine with git 1.6. Per the discussion at http://www.spinics.net/lists/git/msg71059.html, I had to add an extra line to .bashrc for my git user: export PATH=$(git --exec-path):$PATH
  3. Ian White

    Ian White Says:

    Thanks drwestco, added to main article body.
  4. Pixueto

    Pixueto Says:

    I am getting an error when running git from my local machine. I belive there is a problem with the paths even after following comments by Ian. When I log in using git account, the path does not show the git --exec-path. However, if I execute manually execute "bash" then in that shell, the path is ok. Did any1 have this problem?
  5. Pixueto

    Pixueto Says:

    I am getting an error when running git from my local machine. I belive there is a problem with the paths even after following comments by Ian. When I log in using git account, the path does not show the git --exec-path. However, if I execute manually execute "bash" then in that shell, the path is ok. Did any1 have this problem?
  6. Steve

    Steve Says:

    I went through the steps on a MacMini I'm using as a server, and it works great for anyplace off the server, but when I try to clone on the server itself (for deployment) it asks for the password. I notice I can SSH as git from other machines on the network, but I can't SSH to localhost on the server itself as git. I suppose that's the problem, but not sure how to fix it . . .
  7. Steve

    Steve Says:

    Finally figured it out - a line in ~/.ssh/config on the server left over from something done ages ago that was keeping it from working. Don't forget to check the config files: http://developer.apple.com/documentation/Darwin/Reference/ManPages/man5/ssh_config.5.html
  8. Vincent Toms

    Vincent Toms Says:

    I got up to the point where I created a user and so forth, but I get the error "bash: gitosis-serve: command not found" when I run the bash: gitosis-serve: command not found command
  9. Justin Henzie

    Justin Henzie Says:

    I have completed the setup as instructed however, every time I try to ssh either to git or to clone the gitosis-admin repository I am prompted for a password. My understanding was that sudo dscl . create users/git Password '*' is equivalent to useradd --disable-password. Any ideas why this is happening
  10. Ian White

    Ian White Says:

    Hi sorry, for the lack of replies! Even though it's late, here they are.
    @steve (re: can't ssh to repo from local machine) - I was going to say that it looks like your public key isn't getting passed when you do a local ssh - did your sshconfig have that effect?
    @Pixueto @Vincent (re: paths) I guess that you could always manually add the result of 'git --exec-path' to the git user's .bash_rc or .profile (Vincent, your problem is caused by gitosis-serve not being in the PATH - which either means it wasn't installed properly, or the PATH env var doesn't include its location)
    @Justin (re: prompted for password) This probably means that some isn;t right with your public key - hence ssh is falling back to passwords (which it will do, even if there is no password for the account)
  11. Koppehoefer

    Koppehoefer Says:

    Hello… (and thanks for this information source!).

    I’ve followed the above and succeeded great in doing git sitosis-hosting on my Mac at home. Locally, on that machine (or via ssh remotely from the office), I am able to do the ‘get clone’ thing on localhost no problem.

    However,.. When remote (e.g., in the office) on a WindowsXP running git version 1.6.1.9.g97c34 no less,.. my ‘git clone’ command in a normal msdos window (i.e., no pre-logging in remotely to the Mac) results in a FATAL ERROR: Nework error : Connection timed out.: The remote end hung up unexpectedly.

    Note that I am able to do other ssh stuff remotely,.. like logging into my my, setting up tunnels etc. etc.

    Can you set me on the right path to success ? Thanks again for your work !

    Shawn

  12. Koppenhoefer

    Koppenhoefer Says:

    Ooops! Sorry folks,.. (for wasted bandwidth). My mistake was the address I was using in my ‘git clone’,.. when I tried using the ip address directly it worked fine,.. and then I determined that the machine name I was originally providing was spelled wrong.

    mea culpa ! shawn

    p.s. Is there any way for me to delete my previous message?

  13. Ray Drainville

    Ray Drainville Says:

    Dear Shawn Koppenhoefer,

    Don’t worry about the wasted bandwidth—and I’m glad that you’ve figured out your problem :)

    Best,

    Ray

  14. Sonny

    Sonny Says:

    Hello, great article mate! I’m having some trouble though. Whenever I run:

    ssh git@localhost

    I get the following error:

    PTY allocation request failed on channel 0 ERROR:gitosis.serve.main:Need SSH_ORIGINAL_COMMAND in environment. Connection to localhost closed.

    Any thoughts?

  15. mOlind

    mOlind Says:

    first difference: Initialized empty Git repository in /Users/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /Users/git/repositories/gitosis-admin.git/ i can’t get correct message when init repo.

    next, when i trying to clone repo from remote machine: molind$ git clone git@80.249.94.226:gitosis-admin.git Initialized empty Git repository in /Users/molind/gitosis-admin/.git/ Password: fatal: ‘gitosis-admin.git’: unable to chdir or not a git archive fatal: The remote end hung up unexpectedly

    yes, i create password for git user. and it ask me about it. what can be wrong with it?