代码如下:
# su - git
$ ssh git@127.0.0.1
------------------------------------------------
PTY allocation request failed on channel 0
ERROR:gitosis.serve.main:Need SSH_ORIGINAL_COMMAND in environment.
Connection to gitserver closed.
------------------------------------------------
说明 Gitosis 认出了该用户的身份,但由于没有运行任何 Git 命令,所以它切断了连接。那么,现在运行一个实际的 Git 命令 — 克隆 Gitosis 的控制仓库:
在你本地计算机上克隆git仓库
代码如下:
# cd /tmp
# git clone git@gitserver:gitosis-admin.git
这会得到一个名为 gitosis-admin 的工作目录,主要由两部分组成:
红色为git仓库配置,蓝色为实际仓库保存的文件
代码如下:
# cd gitosis-admin
# ll -a
----------------------------------------------------------
total 20
drwxr-xr-x 4 git git 4096 Aug 12 13:21 .
drwxr-xr-x 4 git git 4096 Aug 12 13:23 ..
drwxr-xr-x 8 git git 4096 Aug 12 13:22 .git
-rwxr-xr-x 1 git git 157 Aug 12 13:21 gitosis.conf
drwxr-xr-x 2 git git 4096 Aug 12 13:20 keydir
-----------------------------------------------------------
以上操作相当于,系统git用户初始化并成为gitosis管理员,且利用其管理员权限将gitosis-admin仓库clone到本地.
5.添加本地用户john和仓库test到gitosis,并和管理员git合作管理gitosis
1. 用户john添加并发送id_rsa.pub给git
代码如下:
# su -
# useradd john & passwd john
# su - john
# ssh-keygen -t rsa
-----------------------------------------------------------
Generating public/private rsa key pair.
Enter file in which to save the key (/home/john/.ssh/id_rsa):
Created directory '/home/john/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/john/.ssh/id_rsa.
Your public key has been saved in /home/john/.ssh/id_rsa.pub.
-----------------------------------------------------------
# cp /home/john/.ssh/id_rsa.pub /tmp
2. gitosis管理员git分配john权限
代码如下:
# su - git
# mkdir projects
# cd ~/projects
# git clone git@node2.example.com:gitosis-admin
# cd gitosis-admin
# cat gitosis.conf
------------------------------------------------
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = git@node2.example.com
------------------------------------------------
# ls keydir/
-------------------------
git@node2.example.com.pub
-------------------------
# cp /tmp/id_rsa.pub keydir/john.pub
# vi gitosis.conf
————————————————————————————————————
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = git@node2.example.com
[group test]
writable = test
members = git@node2.example.com john
————————————————————————————————————
# git add .
# git commit -am "add member john and project foo"
# git push
3. 用户git添加项目test
代码如下:
# su - git
# cd ~/projects
# mkdir test
# cd test
# git init
# echo "Hello World." > hello.txt
# git add hello.txt
# git commit -am 'first commit'
# git remote add origin git@node2.example.com:test.git
# git push origin master
4. 用户 john clone test并修改hello.txt
代码如下:
# su - john
# git clone git@node2.example.com:test.git
# cd test
# date >> hello.txt
# git commit -am 'add time to hello.txt' && git push
整个过程分为:
1.通过修改gitosis-admin管理gitosis用户权限,需要clone到本地,然后修改配置文件,最后add push将结果推送到远程实现权限修改.
2.添加系统用户,生成该用户公钥,并将其复制到keydir下,实现该用户有权限进行git等相关操作.
3.登陆该用户账户进行git相关操作,修改完后commit,push到中服务器即可完成仓库权限配置.
七.安装gitweb
1.首先我们需要Git的源码,其中带有GitWeb,并能生成定制的CGI脚本: