参见:http://blog.yuqiyu.com/git-gitolite-server.html
Step1:生成 SSH KEY
gitadmin@gitserver:~$ ssh-keygen -t rsa
上传公钥到服务端
在上传公钥
之前,为了后期方便区分,我们来给id_rsa.pub
文件修改下名称,命令如下所示
gitadmin@gitserver:~/.ssh$ mv id_rsa.pub git_admin.pub
Step2:添加Git管理用户gitadmin@gitserver:~$ sudo adduser git
系统用户创建完成后我们需要切换到该用户
进行安装Gitolite
以及对Gitolite
进行初始化,命令如下所示:
git@gitserver:~$ sudo apt-get install gitolite3
执行完成后在终端会输出初始化管理仓库的消息,如下所示:
Initialized empty Git repository in /var/lib/gitolite3/repositories/gitolite-admin.git/ Initialized empty Git repository in /var/lib/gitolite3/repositories/testing.git/ WARNING: /var/lib/gitolite3/.ssh missing; creating a new one (this is normal on a brand new install) WARNING: /var/lib/gitolite3/.ssh/authorized_keys missing; creating a new one (this is normal on a brand new install) Setting up libcommon-sense-perl (3.74-1build1) ... Setting up libtypes-serialiser-perl (1.0-1) ... Setting up libjson-xs-perl (3.010-2build1) ... 执行设置管理用户: git@gitserver:~$ gitolite setup -pk /tmp/git_admin.pub 这样我们的管理用户已经设置完成了,也就是把我们的gitadmin用户设置成为了服务端的管理用户,只有gitadmin用户才可以操作gitolite-admin仓库内容。 Step3: 再次将用户切换到gitadmin,到gitadmin根目录下执行clone管理仓库gitolite-admin,如下所示: gitadmin@gitserver:~$ git clone git@192.168.0.110:gitolite-admin.git Cloning into 'gitolite-admin'... 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. Checking connectivity... done. gitadmin@gitserver:~$ cd gitolite-admin/ gitadmin@gitserver:~/gitolite-admin$ ls conf keydir Step4: Add the user pub and commit user to git gitadmin@gitserver:~/gitolite-admin/keydir$ cp /media/gitadmin/Ubuntu\ 16.04.5\ LTS\ amd64/ keven.pub gitadmin@gitserver:~/gitolite-admin/keydir$ ls git_admin.pub keven.pub gitadmin@gitserver:~/gitolite-admin/keydir$ ls -l total 8 -rw-rw-r-- 1 gitadmin gitadmin 400 2月 19 13:52 git_admin.pub -rwxrwxrwx 1 gitadmin gitadmin 415 2月 19 10:03 keven.pub gitadmin@gitserver:~/gitolite-admin/keydir$ git add keven.pub gitadmin@gitserver:~/gitolite-admin/keydir$ git commit -m "add user keven" gitadmin@gitserver:~/gitolite-admin/keydir$ git push Step5: 配置新用户权限 gitadmin@gitserver:~/gitolite-admin/conf$ vim gitolite.conf 1 repo gitolite-admin 2 RW+ = gitadmin 3 4 repo testing 5 RW+ = @all 6 7 repo bsp500 8 RW+ = terry 9 RW+ = keven Step6: 提交gitolite.conf gitadmin@gitserver:~/gitolite-admin/conf$ git status gitadmin@gitserver:~/gitolite-admin/conf$ git add gitolite.conf gitadmin@gitserver:~/gitolite-admin/conf$ git commit -m "add keven user" [master 834ff2d] add keven user 1 file changed, 1 insertion(+) gitadmin@gitserver:~/gitolite-admin/conf$ git push Step7:切换到keven 用户去clone keven@gitserver:~$ git clone git@192.168.0.105:bsp500.git Cloning into 'bsp500'... warning: You appear to have cloned an empty repository. Checking connectivity... done.
创建一个新仓库 step1:gitadmin@gitserver:~/gitolite-admin/conf$ vim gitolite.conf 1 repo gitolite-admin 2 RW+ = gitadmin 3 4 repo testing 5 RW+ = @all 6 7 repo bsp500 8 RW+ = terry 9 RW+ = keven 10 11 repo proj_a 12 RW+ =keven gitadmin@gitserver:~/gitolite-admin/conf$ git add . gitadmin@gitserver:~/gitolite-admin/conf$ git commit -m "add a new repo" [master 2bedbdf] add a new repo 1 file changed, 4 insertions(+) gitadmin@gitserver:~/gitolite-admin/conf$ git push Step2:切换到git用户查看新仓库 git@gitserver:~/repositories$ ls bsp500.git gitolite-admin.git proj_a.git testing.git