系统:CentOS7
1.安装依赖包
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y
2.安装git
[root@localhost ~]# yum install git
3.创建git用户
[root@localhost ~]# useradd -s /bin/bash git -m
// -s 指定用户shell
// -m 创建用户主目录
4.安装gitolite
克隆gitolite仓库
[git@localhost ~]$ git clone https://github.com/sitaramc/gitolite
创建目录并安装
[git@localhost ~]$ mkdir $HOME/bin
[git@localhost ~]$ gitolite/install -to $HOME/bin
[git@localhost ~]$ ll bin/
total 24
drwxrwxr-x. 2 git git 4096 Jan 23 01:52 commands
-rwxrwxr-x. 1 git git 3083 Jan 23 01:52 gitolite
-rwxrwxr-x. 1 git git 9023 Jan 23 01:52 gitolite-shell
drwxrwxr-x. 3 git git 22 Jan 23 01:52 lib
drwxrwxr-x. 2 git git 92 Jan 23 01:52 syntactic-sugar
drwxrwxr-x. 3 git git 166 Jan 23 01:52 triggers
-rw-rw-r--. 1 git git 19 Jan 23 02:01 VERSION
drwxrwxr-x. 2 git git 174 Jan 23 01:52 VREF
安装gitolite,出现如下错误
Can't locate Data/Dumper.pm in @INC (@INC contains: /home/git/gitolite/src/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /home/git/gitolite/src/lib/Gitolite/Common.pm line 65.
BEGIN failed--compilation aborted at /home/git/gitolite/src/lib/Gitolite/Common.pm line 65.
Compilation failed in require at gitolite/install line 15.
BEGIN failed--compilation aborted at gitolite/install line 15.
安装如下依赖
yum install -y perl-Data-Dumper
5.配置gitolite管理员
- 5.1. git用户生成公钥
[git@localhost ~]$ cd ~
[git@localhost ~]$ ssh-keygen -t rsa //一路回车
[git@localhost ~]$ mv .ssh/id_rsa.pub admin.pub
- 5.2 安装管理员公钥
[git@localhost ~]$ $HOME/bin/gitolite setup -pk admin.pub
- 5.3 clone 管理员仓库
[git@localhost ~]$ git clone git@127.0.0.1:gitolite-admin
6.添加用户
添加用户很简单。为了添加一个名为highgo的用户,获取该用户的公钥,命名为highgo.pub,然后放到管理员仓库gitolite-admin的keydir目录下。添加,提交,然后推送更改。这样用户就被添加了。
highgo:
[highgo@localhost ~]$ ssh-keygen -t rsa
[highgo@localhost ~]$ mv .ssh/id_rsa.pub highgo.pub
将highgo.pub文件放入/home/git/gitolite-admin/keydir
git:
[git@localhost keydir]$ pwd
/home/git/gitolite-admin/keydir
[git@localhost keydir]$ ll
total 8
-rw-rw-r--. 1 git git 407 Jan 23 02:26 admin.pub
-rw-r--r--. 1 git git 410 Jan 23 02:28 highgo.pub
[git@localhost keydir]$ cd ..
[git@localhost gitolite-admin]$ git add keydir/highgo.pub
[git@localhost gitolite-admin]$ git config --global user.email "git@test.com"
[git@localhost gitolite-admin]$ git config --global user.name "git"
[git@localhost gitolite-admin]$ git commit -am "add user highgo"
[git@localhost gitolite-admin]$ git push origin master
7. 测试
[highgo@localhost ~]$ git clone git@127.0.0.1:testing
Cloning into 'testing'...
warning: You appear to have cloned an empty repository.
[highgo@localhost ~]$ cd testing/
[highgo@localhost testing]$ ll
total 0
[highgo@localhost testing]$ touch text.txt
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:27 text.txt
[highgo@localhost testing]$ git add text.txt
[highgo@localhost testing]$ git config --global user.email "highgo@test.com"
[highgo@localhost testing]$ git config --global user.name "highgo"
[highgo@localhost testing]$ git commit -m "add txt"
[master (root-commit) cc916f3] add txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 text.txt
[highgo@localhost testing]$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 201 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@127.0.0.1:testing
* [new branch] master -> master
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:27 text.txt
[highgo@localhost testing]$ cd ..
[highgo@localhost ~]$ rm -rf testing/
[highgo@localhost ~]$ git clone git@127.0.0.1:testing
Cloning into 'testing'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[highgo@localhost ~]$ cd testing/
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:30 text.txt
[highgo@localhost testing]$