In this tutorial we will learn how to create own git server.This time I have selected Gitolite for git server and gitweb to display git repositories.
Why Gitolite ?
Answer: Easy to setup,have user management through command line,very less memory and cpu usage.
Why Gitweb?
Answer: To display repositories in web interface and view can be manage from Gitolite also.
Operating System: Ubuntu 12.04 LTS
Arch : i686
Git Server IP Address: 10.10.0.16
To setup the gitolite and gitweb follow given below steps
Step 1: Login into your server and become superuser root
linux@ubuntu:~$sudo su -
Step 2: Now install git
# apt-get install git
Step 3: create user git with disabled password and login shell bash
root@ubuntu:~# adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/git git
Step 6: Now login with user git
root@ubuntu:~# su -l git
Step 7: In git directory means /home/git get clone of gitolite with help of git command
git@ubuntu:~$ cd /home/git ; git clone git://github.com/sitaramc/gitolite
Step 7:Create a directory called bin in /home/bin (you are still log in as user git)
git@ubuntu:~$ mkdir $HOME/bin
Step 8: Now install the git (After git clone, the directory gitolite you can see in /home/git. It has the setup files)
git@ubuntu:~$ gitolite/install -ln
Step 9 : After hitting the command “gitolite/install -ln” , just check in bin directory.Is new gitolite file created itself or not
git@ubuntu:~$ ls bin/gitolite bin/gitolite git@ubuntu:~$
Step 10: Now login into your linux system or pc from where you want to manage the Git Server as Git-Admin. Here we will create RSA key and this RSA key we will move to gitolite server.
If you already have RSA key in $HOME/.ssh ,you can skip this step.
Create RSA key, after hiting the command just press enter when it ask for passphrase.
linux@tuxworld:~$ ssh-keygen -t rsa -C "Git-Admin" Generating public/private rsa key pair. Enter file in which to save the key (/home/linux/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/linux/.ssh/id_rsa. Your public key has been saved in /home/linux/.ssh/id_rsa.pub. The key fingerprint is: 9c:96:f3:4e:cb:8e:59:6b:76:05:87:cf:ff:7b:76:93 Git-Admin The key's randomart image is: +--[ RSA 2048]----+ | | | | | . | | . o o . | | S = | | . o + | | + . ..| | Boo. E=| | o+*. oB| +-----------------+ linux@tuxworld:~$
Step 11: Now from your system scp the key into git server.
scp ~/.ssh/id_rsa.pub username@git-server-FQDN-or-its-ip-address:~
linux@tuxworld:~$ scp ~/.ssh/id_rsa.pub linux@10.10.0.16:~ linux@10.10.0.16's password: id_rsa.pub 100% 391 0.4KB/s 00:00 linux@tuxworld:~$
Step 12: Now login back to git server and become superuser , move & rename the id_rsa.pub to /home/git as Git-Admin.pub,change its ownership and group to git and and then login with user git again
linux@tuxworld:~$ ssh linux@10.10.0.16
linux@10.10.0.16’s password:
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)* Documentation: https://help.ubuntu.com/
System information as of Fri May 31 22:27:03 IST 2013
System load: 0.0 Processes: 68
Usage of /: 7.3% of 13.67GB Users logged in: 1
Memory usage: 8% IP address for eth0: 10.0.2.15
Swap usage: 0% IP address for eth1: 10.10.0.16Graph this data and manage this system at https://landscape.canonical.com/
Last login: Fri May 31 22:02:48 2013 from 10.10.0.9
linux@ubuntu:~$
linux@ubuntu:~$ sudo su –
[sudo] password for linux:
root@ubuntu:~#
linux@ubuntu:~$ sudo mv id_rsa.pub /home/git/Git-Admin.pub ; sudo chown git:git /home/git/Git-Admin.pub
[sudo] password for linux:
linux@ubuntu:~$
root@ubuntu:~# su -l git
git@ubuntu:~$
git@ubuntu:~$
git@ubuntu:~$ whoami
git
git@ubuntu:~$
Step 13: Now setup the Git Admin. See the below files and directories are also created.
git@ubuntu:~$ bin/gitolite setup -pk Git-Admin.pub Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/ Initialized empty Git repository in /home/git/repositories/testing.git/ WARNING: /home/git/.ssh missing; creating a new one WARNING: /home/git/.ssh/authorized_keys missing; creating a new one git@ubuntu:~$
Step 14: See some more important files and folder are created but they are hidden.
git@ubuntu:~$ ls -la total 48 drwxr-xr-x 7 git git 4096 May 31 22:39 . drwxr-xr-x 4 root root 4096 May 31 22:03 .. -rw------- 1 git git 160 May 31 22:31 .bash_history drwxrwxr-x 2 git git 4096 May 31 22:05 bin -rw-r--r-- 1 git git 391 May 31 22:23 Git-Admin.pub drwxr-xr-x 5 git git 4096 May 31 22:05 gitolite drwxrwxr-x 6 git git 4096 May 31 22:39 .gitolite -rw-rw-r-- 1 git git 5179 May 31 22:39 .gitolite.rc -rw-rw-r-- 1 git git 12 May 31 22:39 projects.list drwxrwxr-x 4 git git 4096 May 31 22:39 repositories drwx------ 2 git git 4096 May 31 22:39 .ssh git@ubuntu:~$
Step 15: If you do “ls -la repositories” you can find two repo bydefault created.
One is for git admin purpose and second is testing repo
git@ubuntu:~$ ls -la repositories/ total 16 drwxrwxr-x 4 git git 4096 May 31 22:39 . drwxr-xr-x 7 git git 4096 May 31 22:39 .. drwxrwxr-x 8 git git 4096 May 31 22:39 gitolite-admin.git drwxrwxr-x 7 git git 4096 May 31 22:39 testing.git git@ubuntu:~$
Step 16: Login back to your system where you created for the Git-Admin RSA key.
In youremail@example.com replace with your email id.
linux@tuxworld:~$ sudo apt-get install git linux@tuxworld:~$ cd ~/Desktop linux@tuxworld:~$ git config --global user.name "Git-admin" linux@tuxworld:~$ git config --global user.email "youremail@example.com" linux@tuxworld:~$ linux@tuxworld:~$ git config --list user.name=Git-admin user.email=youremail@example.com linux@tuxworld:~$
Now clone the gitolite-admin.git from git server
linux@tuxworld:~/Desktop$ git clone git@10.10.0.16:gitolite-admin.git Cloning into 'gitolite-admin'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. Receiving objects: 100% (6/6), 736 bytes, done. remote: Total 6 (delta 0), reused 0 (delta 0) linux@tuxworld:~/Desktop$
Now gitolite-admin directory will be present after cloneing from git server.
The gitolite.conf is mainly use for User and group ACL for git server.
Now from your system you can easily manage the user group ACL. But for this you have to do “git push”
linux@tuxworld:~/Desktop$ linux@tuxworld:~/Desktop$ cd gitolite-admin/ linux@tuxworld:~/Desktop/gitolite-admin$ ls conf keydir linux@tuxworld:~/Desktop/gitolite-admin$ cd conf/ linux@tuxworld:~/Desktop/gitolite-admin/conf$ linux@tuxworld:~/Desktop/gitolite-admin/conf$ ls gitolite.conf linux@tuxworld:~/Desktop/gitolite-admin/conf$ cat gitolite.conf repo gitolite-admin RW+ = Git-Admin repo testing RW+ = @all linux@tuxworld:~/Desktop/gitolite-admin/conf$
How to push new changes of gitolite.conf into git server from my system
Use the given below command to push the changes into Git Server.
Go to gitolite-admin cloned directory and change to conf directory also. Edit the changes in gitolite.conf and push the code with given below command.
$ cd ~/Desktop/gitolite-admin/conf $ls -l gitolite.conf $git add gitolite.conf $git commit -m "first commit" $git push origin master
Note: “git pull” command is for pull the Version files/directory from Git Server.
Install and Configure Gitweb
Step 18: Login back to git server and become super user root
$ sudo su -
root@ubuntu:~# apt-get install gitweb apache2
It will install gitweb in /usr/share.
In below details you can notice the index.cgi is symlink of gitweb.cgi
root@ubuntu:~# ls -l /usr/share/gitweb/ total 236 -rwxr-xr-x 1 root root 236227 Apr 11 2012 gitweb.cgi lrwxrwxrwx 1 root root 10 Apr 11 2012 index.cgi -> gitweb.cgi drwxr-xr-x 2 root root 4096 May 31 22:04 static root@ubuntu:~#
Step 19: Edit the /home/git/.gitolite.rc and change the UMASK value as 0027
root@ubuntu:~# vi /home/git/.gitolite.rc
# configuration variables for gitolite
# This file is in perl syntax. But you do NOT need to know perl to edit it --
# just mind the commas, use single quotes unless you know what you're doing,
# and make sure the brackets and braces stay matched up!
# (Tip: perl allows a comma after the last item in a list also!)
# HELP for commands can be had by running the command with "-h".
# HELP for all the other FEATURES can be found in the documentation (look for
# "list of non-core programs shipped with gitolite" in the master index) or
# directly in the corresponding source file.
%RC = (
# ------------------------------------------------------------------
# default umask gives you perms of '0700'; see the rc file docs for
# how/why you might change this
UMASK => 0027,
# look for "git-config" in the documentation
Then save and exit by pressing esc key first then typing :wq and hit enter
Step 20: This one is important ,now edit /etc/gitweb.conf file and change the given below two lines only
root@ubuntu:~# vi /etc/gitweb.conf $projectroot = "/home/git/repositories/"; $projects_list = $projectroot;
NOTE: Below given step is deleted and should not be followed with new gitweb version 1:1.7.9.5-1. If you have older version you can try this step.
Step 20:Edit /usr/share/gitweb/gitweb.cgi and change the value of $projectroot as “/home/git/repositories” and $projects_list as “/home/git/projects.list”
root@ubuntu:~# vi /usr/share/gitweb/gitweb.cgi
our $projectroot = “/home/git/repositories/”;
our $projects_list = “/home/git/projects.list”;
edit /etc/gitweb.conf file and change the given below two lines only
root@ubuntu:~# vi /etc/gitweb.conf
$projectroot = “/home/git/repositories/”;
$projects_list = “/home/git/projects.list”;
Step 21: Now restart the apache2 and open the web browser and type http://git-server-ip/gitweb . In my practical case I will type http://10.10.0.16/gitweb
Note: gitweb apache config file is located in /etc/apache2/conf.d/gitweb
root@ubuntu:~# /etc/init.d/apache2 restart
Securing Gitweb with htpasswd
With above screenshot we can see the gitweb web page is accessable to all. To configure it more secure and make as ,it will ask user name and password, we will use htpasswd in apache.
configure htpasswd access in gitweb. Edit the file /etc/apache2/conf.d/gitweb
root@ubuntu:~# vi /etc/apache2/conf.d/gitweb Alias /gitweb /usr/share/gitwebOptions FollowSymLinks +ExecCGI AddHandler cgi-script .cgi AllowOverride None Order allow,deny Allow from all AuthType Basic AuthName "Git Access" Require valid-user AuthUserFile /etc/apache2/gitweb-htpasswd root@ubuntu:~#
Create htpasswd username and passwd.
in below eg. admin is user name.
root@ubuntu:~# htpasswd -mc /etc/apache2/gitweb-htpasswd admin New password: Re-type new password: Adding password for user admin root@ubuntu:~#
Now restart the apache2
root@ubuntu:~# /etc/init.d/apache2 restart
Now open the browser and type once again http://gitserver-ip-address/gitweb
eg. http://10.10.0.16/gitweb
i got a error when i configured separate user in repo access config. any one help me?
configured file : /home/git/.gitolite/conf/gitolite.conf
repo Project_modules
RW+ = admin
its not working..
Thanks for the simplified process but I’m not able to push the changes to the server from a node.
The error state that “[remote rejected] master -> master (hook declined)
Steps taken:
@sever end: copy the id_rsa.pub to git-admin-…/keydir/abc.pub
added the repo in …/conf/gitolite.conf
Then add, commit and pushed changes.
@localend: git clone@IP:.git as git clone@IP:repo.git is not working.
commited the changes but when try to push using “git push origin master” is saying the above error.
Can you please help me out.