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
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.
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! OmarJuly 25th, 2008 at 02:58 AM
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):$PATHAugust 20th, 2008 at 05:44 PM
Ian White Says:
Thanks drwestco, added to main article body.September 23rd, 2008 at 06:47 AM
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?October 3rd, 2008 at 05:43 PM
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?October 3rd, 2008 at 05:43 PM
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 . . .October 6th, 2008 at 11:29 PM
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.htmlOctober 7th, 2008 at 04:10 AM
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 commandNovember 10th, 2008 at 09:44 PM
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 happeningNovember 28th, 2008 at 12:04 AM
Ian White Says:
Hi sorry, for the lack of replies! Even though it's late, here they are.December 1st, 2008 at 07:50 AM
@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)
Koppehoefer Says:
January 29th, 2009 at 12:14 PM
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
Koppenhoefer Says:
January 29th, 2009 at 02:32 PM
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?
Ray Drainville Says:
January 29th, 2009 at 03:29 PM
Dear Shawn Koppenhoefer,
Don’t worry about the wasted bandwidth—and I’m glad that you’ve figured out your problem :)
Best,
Ray
Sonny Says:
March 8th, 2009 at 06:58 AM
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?
mOlind Says:
April 23rd, 2009 at 11:15 AM
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?