git hosting with Leopard
May 19th, 2008
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
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.
July 25th, 2008 at 02:58 AM 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