Howto: Install git, gitosis & gitweb on CentOS 5
Introduction
GIT is a powerful DVCS system. Gitweb is a Web-UI to visualize the repos. Gitosis takes the pain out of managing multiple GIT repos and all the ACL's.
It uses a git repos to manage the git repos with all connections done via a shared ssh/shell account and authentication is done via ssh private/public keys.
Installation
In order to install git, gitweb & gitosis we need to add the EPEL yum repository:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
Once that is done we install git, git-web and gitosis:
yum install git gitweb gitosis
If all went well you should now have all three things installed. Now to setup gitosis to manage our repos.
At the core of gitosis is a special git repos called gitosis-admin The contents of this will be explained soon.
To get started you will want to copy your ssh public key to a tmp place on the server tmp/user.pub and then issue the following command:
sudo -H -u gitosis gitosis-init < /tmp/user.pub
This will setup gitosis ready to serve git repos from /var/lib/gitosis/
On your local machine, you'll now be able to clone the gitosis admin repository with the following command:
git clone gitosis@example.com:gitosis-admin.git
The gitosis-admin repository contains a directory named keydir/ and a file named gitosis.conf.
The keydir/ contains the SSH public keys for your users in files named in the convention of [username].pub. Each user of your git repositories will have their own file in keydir/ the username is for internal gitosis use, and needn't correspond with any shell username.
The gitosis.conf file contains a set of access control rules that can be used to provide people access to a particular repository. An access control block looks like this:
[group devs-rw]
writable = iphone-project wiki drupal7
members = mick alex adam mary
[group devs-ro]
readonly = iphone-project wiki drupal7
members = john
This block gives the users (e.g. keys in the keydir/) "mick", "alex", "adam" and "mary" write(push) access to the iphone-project, wiki & drupal repositories. Note that repositories in the "writable" list needn't exist before a user pushes to them, as gitosis will create the new repositories if needed. Also the user "john" has readonly(clone) access to the same 3 repos. He is not allowed to push.
To create a new repository, just add it to the writable list of a gitosis group. All repositories will have "clone" or "remote" URLs in the following form:
gitosis@example.com:$reponame.git
You may have as many "groups" as you need to support your workflow.
You should now have a fully working gitosis server. All that is left to do is to enable gitweb so that you can visualize all of the repos in one place.
Lucky for us this is almost completely done with the yum install earlier. A simple apache restart and that's it.
The following URL should bring up a working gitweb instance. Of course it will be empty to start with.
http://example.com/git/gitweb.cgi
Note: A repos created with gitosis above will not be visible by default in gitweb. A simple file permission change will take care of this.
chmod 755 /var/lib/gitosis/repositories/$REPOSNAME
Conclusion
You should now have a fully working central git server managed by gitosis and visualised by gitweb.
Cheers Mick
After below step: ¨sudo -H -u gitosis gitosis-init < /tmp/user.pub¨ I met problem: ¨sudo: no passwd entry for gitosis!¨
Could you tell me how to tackle it? Thank you.
Alan,
This error is saying you do not have the
gitosissystem user.Did you install from the EPEL RPM because it will add the user for you?
This should fix it up for you.
Cheers Mick
I'm on CentOS 5.5 with EPEL enabled. The gitweb from EPEL repository is using a different path than gitosis is using.
One needs to edit /usr/share/gitweb/gitweb.cgi and change the repositories from /var/lib/git to /var/lib/gitosis/repositories then everything is ok.
Great tutorial though!