Setting Up Git And Gitosis On CentOS 5.2

Tutorial for setting up Git and Gitosis On CentOS 5.2

Photo of Greg Harvey
Wed, 2010-06-09 15:51By greg

This article is a tweaked version of several tutorials around. Many of the original links courtesy of Adrian Simmons. Thanks to all the others who gave me loads of help in IRC and thanks to Jerad at Lullabot for inspiring me to dive in to Git with this article.

Before you start, you'll need to install Git (instructions borrowed from this post on How To Linux).

As root, install the dependencies:

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel gcc

Get the Git source code:

wget http://kernel.org/pub/software/scm/git/git-1.7.1.tar.gz

ntar the Git source code:

Untar xvfz git-1.7.1.tar.gz

Install:

cd git-1.7.1

make prefix=/usr/local all

make prefix=/usr/local install

Then we're in to this Ubuntu article, which I have CentOSified for you. First clone the gitosis repository and run the basic python install. You just need the python setuptools package:

yum install python-setuptools

And then you can easily install Gitosis:

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

cd gitosis

python setup.py install

Next you need to create a user that will own the repositories you want to manage. You can put its home directory wherever you want, but in this example we'll put it in the standard /home location:

adduser -r --shell /bin/sh -c 'git version control' --home-dir /home/git git

At this point our Ubuntu instructions lose the plot a bit, but it's ok because I found this CentOS article, which is less clear in some places but explains the SSH bits and onwards far better. It says:

The whole point of Gitosis is to transfer files via ssh using a shared key process (i.e. no password required to login to user Git on your server). Now before you go and start doing it the manual way - don't. Gitosis must create and maintain the authorized_keys file.

So, as your normal user on your local computer (client/development box):

ssh-keygen -t dsa

(I already had one, actually, because I used keys with my old SVN server, so nothing to do here.)

Copy the id_rsa.pub file to the server:

scp ~/.ssh/id_rsa.pub git@yourserver.com:/home/git

As root again and back on the server, gitosis-init is run for the first and only time, loads up your user's key, like this:

su git -c "gitosis-init < /home/git/id_rsa.pub"

Note, because I already had a key set up locally and on the server, I could do this without going to my client machine:

cp /home/myuser/.ssh/authorized_keys /home/git/id_rsa.pub su git -c "gitosis-init < /home/git/id_rsa.pub"

Get rid of the public key we left lying around:

rm /home/git/id_rsa.pub

Now we must set some directory and file permissions to let sshd see the new authorized_keys file:

chmod 755 /home/git

chmod 700 /home/git/.ssh

chmod 644 /home/git/.ssh/authorized_keys

Now, back to your local computer, obviously you need to install Git there too. From here on out you can continue with this article from "Step 7 - (On your client)":

http://nfocipher.com/index.php?op=ViewArticle&articleId=12&blogId=1

Yay! Git on CentOS 5.2.

You're now ready for the big Drupal.org move to Git. =)

Other really useful links include:

http://progit.org/book/ch4-7.html

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secu...

http://yehudakatz.com/2010/05/13/common-git-workflows/ (Thanks to Stew Robinson for that one.)

And if you're an SVN user like me:

http://www.lullabot.com/blog/making-transition-git

http://markmcb.com/2008/10/18/3-reasons-to-switch-to-git-from-subversion

Enjoy.