说明:本次测试使用的是 ubuntu16, 用户是root
安装git服务器,关键点 git-core
第一步:更新服务器
apt-get update
第二步:安装核心组件
apt-get install git-core openssh-server openssh-client
配置git用户
第三步:添加git 系统用户及 指定 git 用户组,并且指定相应的shell.
adduser –system –shell /bin/bash –group git
执行后的效果:
root@iZuf6f244t8ycx65un19waZ:~# adduser --system --shell /bin/bash --group git
Adding system user `git' (UID 110) ...
Adding new group `git' (GID 119) ...
Adding new user `git' (UID 110) with group `git' ...
Creating home directory `/home/git' ...
第四步:添加git 帐号到 ssh组,防止 git帐号不能远程使用 adduser git ssh
root@iZuf6f244t8ycx65un19waZ:~# adduser git ssh
Adding user `git' to group `ssh' ...
Adding user git to group ssh
Done.
第六步:更新git帐号密码 passwd git
root@iZuf6f244t8ycx65un19waZ:~# passwd git
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
配置git仓库
第七步:创建仓库文件夹
mkdir /home/git/repositories
第八步:改变所属组及所有者
chown git:git /home/git/repositories
第九步:设置目录权限
chmod 755 /home/git/repositories
在对应的位置初始化空仓库:
root@iZuf6f244t8ycx65un19waZ:/home/git/repositories# git init --bare
执行效果:
Initialized empty Git repository in /home/git/repositories/
安装gitosis 配置权限策略
Gitosis 就是一套用来管理 authorized_keys文件和实现简单连接限制的脚本。简单地说,Gitosis就是git的权限策略控制器。
因为安装gitosis 需要python的 setuptools 工具,所以需要安装一下这个工具
第十步:安装python工具
apt-get install python-setuptools
第十一步:下载/克隆 gitosis 源码
git clone https://github.com/res0nat0r/gitosis.git
注意:中间的两个是0 ,数字0.
第十二步:安装 gitosis工具,
cd gitosis/
python setup.py install
执行结果:
Using /usr/lib/python2.7/dist-packages
Finished processing dependencies for gitosis==0.2