一、 安装git
1. # yum update
# yum installcurl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
# mkdir -p/data/git
# groupadd git
# useradd -g git-d /data/git -s /bin/bash git
# passwd git //设置git用户密码
2. 改变git目录权限
# chown -Rgit:git /data/git
# chmod -R 2755/data/git
3.下载git
$ wget https://www.kernel.org/pub/software/scm/git/git-2.6.2.tar.gz
$ tar -xzvfgit-1.7.2.3,tar.gz
$ cdgit-1.7.2.3
$ ./configure--with-curl=/usr/local
$ make &&make install
$ ln -s /usr/local/git/bin/* /usr/bin/
$ git--version #查看版本号,确实git是否安装成功
二、 安装gitolite
# su –git
$ pwd
/data/git
$ mkdirbin
$ ls
$ git clone https://github.com/sitaramc/gitolite.git
或者git clonegit://github.com/ossxp-com/gitolite.git
$ ls
bin gitolite
$ ./gitolite/install --to /home/git/bin/
$ ls bin/
commands gitolite gitolite-shell lib syntactic-sugar triggers VERSION VREF
三、 客户端生成密钥对,为gitolite配置管理员
1.Windows安装git forwindows2.6.2,安装完后打开Git Bash
$ ssh-keygen–f admin –C [email protected]
$ scpadmin.pub [email protected]:/tmp/admin.pub
2. 切换到git用户,为gitolite配置管理员
$ 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
(this is normal on a brand new install)
WARNING: /home/git/.ssh/authorized_keys missing; creating a new one
(this is normal on a brand new install)
$ ls
bin gitolite projects.list repositories
四、 服务器ssh开启公钥登录
1. vim/etc/ssh/sshd_config,将下面几句前面的#号去掉
RSAAuthenticationyes
PubkeyAuthenticationyes
AuthorizedKeysFile .ssh/authorized_keys
AuthorizedKeysCommandnone
AuthorizedKeysCommandRunAsnobody
2.重启ssh
service sshdrestart
五、 配置gitolite,添加用户,添加库,用户权限管理
1. windows安装TortoiseGit
2. 新建git文件夹,进入,右键Git Clone…
URL: [email protected]:gitolite-admin.git
勾选Load Putty Key,选择你的私钥(此处需使用ppk格式私钥,可以使用puttygen将私钥admin转换成admin.ppk)
点击OK即可clone服务器上的gitolite-admin文件夹到本地
3. 添加用户
管理员将其他用户的公钥(如dong.pub)复制到gitolite-admin/keydir/下
4. 添加库
进入gitolite-admin/conf/,右键Git Bash Here,
$ vimgitolite.conf (此文件用于添加库和配置用户对库的权限)
repo gitolite-admin
RW+ = admin
repo testing
RW+ = @all
repo git-dong #新建库git-dong
RW+ = admin dong #设置用户admin dong有读写权限
将修改push到服务器,即可添加库和用户。
$ cd ..
$ gitstatus #查看git库状态
$ gitadd keydir/dong.pub conf/gitolite.conf 或者git add .
$ gitcommit –m “add repo git-admin;add user dong”
进入gitolite-admin文件夹,右键TortoiseGitPush
点击OK即可。
5. 用户权限管理
在客户端clone gitolite-admin.git,编辑gitolite-admin/conf/gitolite.conf配置各用户权限。
1 @team1 = zc
2 @team2 = aws zc
3 repo gitolite-admin
4 RW+ = admin
5
6 repo ossxp/.+
7 C = admin
8 RW = @all
9
10 repo testing
11 RW+ = admin
12 RW master = dong
13 RW+ pu = shuai
14 RW cogito$ = lijun
15 RW bw/ = houhou
16 - = anony
17 RW tmp/ = @all
18 RW refs/tags/v[0-9] = dongshuai