gitosis安装配置详解
所需环境(linux)CentOS【我用的是7】
所需软件:git python gitosis openssh-client
具体步骤:
服务器端:
有两个用户(同一台机子,当然你可以用两台机子):一个是作为管理者用户qjjia(管家),一个用户(git)代码托放者(可以理解为仓库)
1
2
# useradd -m git#创建一个git账户作为服务端的仓库
# passwd git
将该用户作加入sudoers里:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# vim /etc/sudoers
root ALL=(ALL) ALL#直接将用户添加到sudo组里
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheelALL=(ALL) ALL #将wheel组中的所有用户添加到sudo组
%dlp ALL=(ALL) ALL #将dlp组中的所有用户添加到sudo组
在此,我将git用户填加到dlp组中
usermod -G dlp git
检查有没有添加成功
# groups git
git : git dlp
# su - cola//切换到管理者用户 cola
安装相关软件
1
2
3
4
5
$ yum install git#安装git
$ sudo yum install python python-setuptools #安装python环境
$ git clone git://github.com/res0nat0r/gitosis.git#下载gitosis
$ ls
gitosis
编译安装gitosis
1
2
$ cd gitosis/
$ sudo python setup.py install
生成管家qjjia的公钥,用于初始化使用
1
$ ssh-keygen -t rsa
将生成的公钥拷贝存放在/tmp/cola/中
1
$ cp ~/.ssh/id_rsa.pub /tmp/cola/
用服务器端生成的公钥初始化gitosis,下面一步很关键,请注意!!!
1
2
3
4
5
6
7
8
9
$ cd gitosis/
$ sudo -H -u git gitosis-init < /tmp/cola/id_rsa.pub
$ su git ####切换至git账户查看~/下的文件
$ ls
gitosisrepositories
$ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
切换回管家qjjia账户,从git账户的目录下(~/repositories/gitosis-admin.git)clone gitosis-admin.git管理平台(这玩意分配账户权限和项目名,对应账户的公钥)
git clone git@localhost:gitosis-admin (这步骤应该是不需要密码的,应为你是用qjjia的公钥初始化gitosis的)
1
2
3
4
5
6
$ ll
drwxr-xr-x. 4 qjjia dlp 49 Jul9 15:05 gitosis-admin
cd进入,你会发现如下两个文件
$ ls
gitosis.conf (分配账户权限的文件)keydir(这个是目录,存放账户的公钥)
配置账户权限giosis.comf,第一次打开,内容如下
1
2
3
4
5
6
$ vim gitosis.conf
#组名
members = qjjia@genitus-86-092#账户名,注意要与keydir目录下的 公钥名一致,但keydir的公钥名有扩展名.pub
writable = gitosis-admin#托管的项目名,一般为文件夹名字
针对members的补充:如qjjia@genitus-86-092 对应的公钥名为qjjia@genitus-86-092.pub
然后做如下修改,新填两个用户M 和long 对项目cola进行控制,其对应的公钥为M.pub long.pub
1
2
3
4
5
6
7
8
9
10
11
$ vim gitosis.conf
members = qjjia@genitus-86-092
writable = gitosis-admin
members = M long qjjia@genitus-86-092
writable = cola
然后在对应的客户端 M 和 long 的机子上生成自己的公钥,上传账户M 和 long 的公钥到 服务端qjjia账户的keydir目录中,结果如下
1
2
3
4
5
$ ll
total 12
-rw-r--r--. 1 qjjia dlp 400 Jul9 14:20 long.pub
-rw-r--r--. 1 qjjia dlp 397 Jul9 15:04 M.pub
-rw-r--r--. 1 qjjia dlp 402 Jul9 14:20 qjjia@genitus-86-092.pub
这里举一个例子,在客户端cola下生成公钥上传到keydir的步骤:
在long的主机上
1
$ ssh-keygen -t rsa#然后一路回车
在qjjia的主机上
1
$ scp long@192.168.86.92:/home/long/.ssh/id_rsa.pub ./
完成了公钥上传到keydir工作后
做如下操作,将gitosis-admin的修改信息上传至git账户的代码仓库
先回退到gitosis-admin目录
1
2
3
4
$ cd gitosis-admin/
git add .
git commit -am "add member john and project foo"
git push
在qjjia账户下创建cola项目目录,完成初始化,提交给git仓库
1
2
3
4
5
6
7
8
9
cd ~
mkdir cola
cd cola
git init
touch hello.txt
git add hello.txt
git commit -am 'first commit'
git remote add origin git@localhost:cola.git
git push origin master
下面都是客户端的操作:
客户端账户long从仓库clone cola.git,并添加一个新文件hello
1
2
3
4
5
6
$ git clone git@192.168.86.92:cola.git
$ cd cola
$ touch hello
$ git add hello
$ git commit -am "add hello file!"
$ git push
客户端账户M从仓库clone cola.git,并添加一个新文件sb
1
2
3
4
5
6
7
$ git clone git@192.168.86.92:cola.git
$ cd cola
$ ls
hellohello.txt
$ git add sb
$ git commit -am "add sb"
$ git push
客户端账户long从仓库 git pull 文件
1
2
3
$ git pull
$ ls
hellohello.txtsb
常见问题:
git操作需要输入密码
[*]原因
[*]公密未找到
[*]解决
[*]上传id_pub.rsa到keydir并改为'gitosis帐号.pub'形式,如long.pub。扩展名.pub不可省略
页:
[1]