CentOS6.*安裝gitolite

CentOS6.*安裝gitolite

安裝基礎包

# yum install perl openssh git node

建立git用戶

# adduser git
# passwd git
git

在git用戶家目錄下安裝gitolite

切換到git用戶 github

# su – git shell

建立文件夾bin ubuntu

$ mkdir bin

克隆gitolite源碼 vim

$ git clone https://github.com/sitaramc/gitolite.git
$ ls
bin  gitolite
服務器

安裝gitolite app

$ ./gitolite/install -to /home/git/bin/ ssh

$ cd bin/
$ ls
commands  gitolite  gitolite-shell  lib  syntactic-sugar  triggers  VERSION  VREF
ide

配置gitolite管理員

生成管理員帳戶的公鑰(此處指定本地root用戶爲管理員,鍵入回車使用默認值)

# ssh-keygen


複製管理的公鑰

# cp .ssh/id_rsa.pub /tmp/admin.pub


切換回git用戶,爲gitolite配置管理員

$ /home/git/bin/gitolite setup -pk /tmp/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


$ ls
bin  gitolite  projects.list  repositories

管理員平常管理

管理員clone管理庫(此處爲本地root用戶)

# git clone git@192.168.213.130:gitolite-admin
Initialized empty Git repository in /root/gitolite-admin/.git/
The authenticity of host '192.168.213.130 (192.168.213.130)' can't be established.
RSA key fingerprint is d4:28:ca:66:58:b6:39:c1:aa:37:58:9a:5b:ed:50:05.
Are you sure you want to continue connecting (yes/no)? yes
# 此處由於第一次ssh鏈接,因此須要輸入’yes’
Warning: Permanently added '192.168.213.130' (RSA) to the list of known hosts.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (6/6), 748 bytes, done.
remote: Total 6 (delta 0), reused 0 (delta 0)


# pwd
/root/gitolite-admin
# ls
conf  keydir

建立庫、添加用戶
例如某test123用戶訪問git服務器上的myFirstRepo庫

test123用戶向git服務器管理(此處是以前的服務器本地的root用戶)提交本身的ssh無密碼公鑰

管理員將test123的公鑰複製到 gitolite-admin/keydir/ 下

# cp test123.pub /root/gitolite-admin/keydir/

管理員建立myFirstRepo庫,並給test123分配權限

# cd gitolite-admin/conf/
# vim gitolite.conf

默認內容爲:

repo gitolite-admin
    RW+ =   admin
repo testing
    RW+ =   @all

下邊定義myFirstRepo庫,而且指定用戶權限:

repo gitolite-admin
    RW+ =   admin
repo testing
    RW+ =   @all
@myGroup=admin  test123
repo myFirstRepo
    RW+ =   @myGroup

此處@myGroup是一個組,給myGroup組賦予對myFirstRepo這個庫的讀、寫、推送的權限(詳細規則可參考gitolite的readme.txt)

管理員將對gitolite-admin的修改(建庫、加用戶)提交到git服務器

# pwd
/root/gitolite-admin
# git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   conf/gitolite.conf
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       keydir/test123.pub
no changes added to commit (use "git add" and/or "git commit -a")

# git add *
# git commit -m "AddRepo:myFirstRepo;AddUser:test123"
[master 4c5a5d0] AddRepo:myFirstRepo;AddUser:test123
Committer: root <root@app-node-V-CC.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
    git commit --amend --author='Your Name <you@example.com>'
2 files changed, 6 insertions(+), 0 deletions(-)
create mode 100644 keydir/test123.pub

提示是建議設置用戶信息(便於多人協做時辨別),可參照提示命令操做(其實git自動爲你添加了)

# git push origin master
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 859 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/myFirstRepo.git/
To git@192.168.213.130:gitolite-admin
48a7307..4c5a5d0  master -> master

客戶驗證

test123用戶克隆myFirstRepo庫

$ git clone git@192.168.213.130:myFirstRepo
Initialized empty Git repository in /home/test123/myFirstRepo/.git/
warning: You appear to have cloned an empty repository.
$ ls
myFirstRepo

test123用戶初始化myFirstRepo庫

$ touch test.sh
$ git add test.sh
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   test.sh
#
$ git commit -m "InitRepo:myFirstRepo"
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.213.130:myFirstRepo
* [new branch]      master -> master

SSH非22端口通訊

本地或gitolite服務器使用非ssh默認端口,會出現錯誤,可經過下列方法解決:

$ vim ~/.ssh/config

添加 以下內容

host ${ip_of_gitolite_server}
port ${port_of_yours}

ubuntu12.04上安裝gitolite,照貓畫虎就行

相關文章
相關標籤/搜索