Monday, March 25, 2013

Install Gitolite that manages Git Repositories.

penguin-centos-logoInstall Gitolite that manages Git Repositories.

Install Gitolite

[root@www ~]# yum --enablerepo=epel -y install gitolite                             # install from EPEL
[root@www ~]# su - gitolitecreate SSH keys for Gitolite admin and Setup with it.

-sh-4.1$ ssh-keygen -t rsa -f ~/.ssh/gitadmin
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):# set passphrase
Enter same passphrase again:# confirm
Your identification has been saved in ./.ssh/gitadmin.
Your public key has been saved in ./.ssh/gitadmin.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx gitolite@www.server.world
The key's randomart image is:

-sh-4.1$ gl-setup ~/.ssh/gitadmin.pub

The default settings in the rc file (/var/lib/gitolite/.gitolite.rc) are fine for most
people but if you wish to make any changes, you can do so now.

hit enter...# Enter

# the gitolite.rc file opens, then close with no edit

-sh-4.1$ vi ~/.ssh/config

# create new
host GitServer                             # any name you like
user gitolite                                 hostname 10.0.0.31                 # Git server's hostname or IP address
port 22
identityfile ~/.ssh/gitadmin                                # specify private key

-sh-4.1$ chmod 600 ~/.ssh/config
-sh-4.1$ git config --global user.name "gitolite"
-sh-4.1$ git config --global user.email "gitolite@server.world"

# clone "gitolite-admin" repository to finish setup
-sh-4.1$ git clone ssh://GitServer/gitolite-admin
Initialized empty Git repository in /var/lib/gitolite/gitolite-admin/.git/
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

Add New User in Gitolite.

Create SSH keys with a User you'd like to add in Gitolite.

[cent@www ~]$ ssh-keygen -t rsa -f ~/.ssh/id_cent
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):               # set passphrase

Enter same passphrase again:                 # confirm

Your identification has been saved in ./.ssh/id_cent.
Your public key has been saved in ./.ssh/id_cent.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx cent@www.server.world
The key's randomart image is:

Pass the SSH public key which a user cerated to Gitolite admin. Next, Add the user with Gitolite admin like follows.

-sh-4.1$ cd ./gitolite-admin/keydir
-sh-4.1$ git add id_cent.pub
-sh-4.1$ git commit -m "Add User cent"
-sh-4.1$ git push origin master
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 708 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)

Make sure if added user can do clone.

[cent@www ~]$ vi ~/.ssh/config             # create new
host GitServer # any name you like

user gitolite    hostname 10.0.0.31      # Git server's hostname or IP address

port 22    identityfile ~/.ssh/id_cent    # specify private key

[cent@www ~]$ chmod 600 ~/.ssh/config

[cent@www ~]$ git config --global user.name "cent"

[cent@www ~]$ git config --global user.email "cent@server.world"

[cent@www ~]$ git clone ssh://GitServer/testing
Initialized empty Git repository in /home/cent/testing/.git/
warning: You appear to have cloned an empty repository.
[cent@www ~]$ ll

total 4

drwxr-xr-x 3 cent cent 4096 Mar 6 14:03 testing   # just done

Add New Repository in Gitolite

Work with Gitolite admin

-sh-4.1$ vi /var/lib/gitolite/gitolite-admin/conf/gitolite.conf

repo    gitolite-admin

RW+     =   gitadmin

repo    testing

RW+     =   @all

# add public-repo

repo    public-repo

RW+     =   @all

-sh-4.1$ cd gitolite-admin

-sh-4.1$ git commit -a -m "Add public-repo repository"

-sh-4.1$ git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 403 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: creating public-repo...
remote: Initialized empty Git repository in /var/lib/gitolite/repositories/public-repo.git/

Make sure a user can clone the repository added.

# show the list of repositories he can access
[cent@www ~]$ ssh GitServer
PTY allocation request failed on channel 0
hello id_cent, this is gitolite 2.3.1-1.el6 running on git 1.7.1
the gitolite config gives you the following access:

@R_ @W_     public-repo

@R_ @W_     testing

Connection to 10.0.0.31 closed.

[cent@www ~]$ git clone ssh://GitServer/public-repo
Initialized empty Git repository in /home/cent/public-repo/.git/
warning: You appear to have cloned an empty repository.
[cent@www ~]$ ll

total 8

drwxr-xr-x 3 cent cent 4096 Mar  6 14:45 public-repo

drwxr-xr-x 3 cent cent 4096 Mar  6 14:03 testing

Configure User Permission for Repositories

For example, add permission for a user "cent" to a repository "public-repo".

-sh-4.1$ cd /var/lib/gitolite/gitolite-admin/conf

-sh-4.1$ vi gitolite.conf

# user name is just the name of SSH key file name

repo    public-repo

RW+     =   id_cent

-sh-4.1$ git commit -a -m "Change Permission for public-repo"

-sh-4.1$ git push

For example, add permission for a group "developer" to a repository "public-repo".

sh-4.1$ cd /var/lib/gitolite/gitolite-admin/conf

-sh-4.1$ vi gitolite.conf

@developer = id_cent id_ubuntu

repo    public-repo

RW     =   @developer

-sh-4.1$ git commit -a -m "Change Permission for public-repo"

-sh-4.1$ git push

For example, set permissions like follows.
* id_redhat has all permission
* deployer group has read/write permission for "prod" branch
* developer group has read/write permission for "dlp" branch

-sh-4.1$ cd /var/lib/gitolite/gitolite-admin/conf

-sh-4.1$ vi gitolite.conf

@developer = id_cent id_ubuntu

@deployer = id_debian id_fedora

repo    public-repo

RW+     =  id_redhat

RW prod =  @deployer

RW dlp  =  @developer

-sh-4.1$ git commit -a -m "Change Permission for public-repo"

-sh-4.1$ git push

 

No comments:

Post a Comment