第一步:安装git
[root@localhost /]# yum install -y git
安装完成后,查看git版本
[root@localhost /]# git --version
git version 1.8.3.1
这样Git 就安装完成了!
第二步:创建公钥和秘钥
[root@localhost /]# ssh-keygen -t rsa
第三步:创建git管理账户
[root@localhost /]# cd /home
[root@localhost /home]# useradd git // 创建账户
[root@localhost /home]# passwd git // 设置密码
第四步:创建git仓库存放目录,以后所有仓库都将放在该目录方便管理
[root@localhost /]# mkdir /home/git/repositories
[root@localhost /]# chown git:git /home/git/repositories // 设置仓库目录所有者为git
[root@localhost /]# chmod 755 /home/git/repositories // 设置仓库目录权限
第五步:安装Python的setup tool
[root@localhost /]# yum install python-setuptools
第六步:获取gitosis 并利用Python 的 setup tool 安装
[root@localhost /]# cd /tmp // 进入tmp目录
[root@localhost /]# git clone https://github.com/res0nat0r/gitosis.git // 获取gitosis
[root@localhost /]# cd gitosis // 进入
[root@localhost /]# sudo python setup.py install // 执行安装 等待安装完成
第七步:配置gitosis
[root@localhost /]# cp ~/.ssh/id_rsa.pub /tmp // 将公钥复制到tmp目录
[root@localhost /]# sudo -H -u git gitosis-init < /tmp/id_rsa.pub // 初始化 gitosis
[root@localhost /]# chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update // 设置权限
第八步:管理gitosis
[root@localhost /]# cd /home/git 进入home目录
[root@localhost /home/git]# git clone git@127.0.0.1/gitosis-admin.git 拉去gitosis 自动创建的一个仓库
[root@localhost /home/git]# cd gitosis-admin/ 进入该目录
说明:gitosis-admin 里面会有一个文件一个目录分别是:gitosis.config,keydir,keydir 该文件是用来存放.pub公钥的。(只有要将公钥放在keydir下,就可以拉去相关授权的仓库了)
gitosis.config是用来管理仓库和用户的,如下图所示:
[gitosis]
[group gitosis-admin]
// 管理用户(多个用户只需继续往后面添加)
members = root@localhost xiaoliu
// 管理仓库 (多个仓库只需继续往后面添加)
writable = gitosis-admin
[group test]
// 公钥文件名字
members = test test2
// 仓库名字
writable = test demo1 demo2 demo3
这样就大工告成了
有问题可在下发留言指出,共同学习,共同交流