Ubuntu10.04上使用gitosis搭建git代码仓库 博客分类: 服务器配置 gitrepositorygitosis
转自http://www.flatws.cn/article/program/python/2011-06-06/29177.html
在Ubuntu 10.04上配置gitosis作为git服务器的操作步骤
在服务器端<server>
#安装所需软件
ubuntu@<server>:~$ sudo apt-get install git-core openssh-server openssh-client
#将git数据保存在/data/repo目录下
ubuntu@<server>:~$ sudo mkdir /data/repo
#使用git用户作为服务器端管理用户
ubuntu@<server>:~$ sudo useradd -m git
ubuntu@<server>:~$ sudo passwd git
#只有git用户有权限
ubuntu@<server>:~$ sudo chown git:git /data/repo
ubuntu@<server>:~$ sudo chmod 700 /data/repo
#配置全局信息
ubuntu@<server>:~$ git config --global user.name "<user name> git server"
ubuntu@<server>:~$ git config --global user.email "<email>"
#安装gitosis
ubuntu@<server>:~$ sudo apt-get install python-setuptools
ubuntu@<server>:~$ cd /tmp
ubuntu@<server>:/tmp$ git clone git://eagain.net/gitosis.git
ubuntu@<server>:/tmp$ cd gitosis
ubuntu@<server>:/tmp/gitosis$ sudo python setup.py install
#链接/data/repo 到 /home/git/repositories
ubuntu@<server>:/tmp/gitosis$ su git
$ ln -s /data/repo /home/git/repositories
$ exit
在客户端<pc1>,将本地的公钥拷到服务器上
<pc1>:~ admin$ scp .ssh/id_dsa.pub git@<server>:/tmp
在服务器端<server>
#让gitosis运行起来
ubuntu@<server>:/tmp/gitosis$ sudo chmod a+r /tmp/id_dsa.pub
ubuntu@<server>:/tmp/gitosis$ sudo -H -u git gitosis-init < /tmp/id_dsa.pub
#如果没有设置过root密码,则设置一下,否则跳过
ubuntu@<server>:/tmp/gitosis$ sudo passwd root
#进去看一眼
ubuntu@<server>:/tmp/gitosis$ su
root@<server>:/tmp/gitosis# cd /home/git/repositories
root@<server>:/home/git/repositories# cd gitosis-admin.git/
root@<server>:/home/git/repositories/gitosis-admin.git# ls
branches description gitosis-export hooks info refs
config gitosis.conf HEAD index objects
root@<server>:/home/git/repositories/gitosis-admin.git# sudo chmod 755 /data/repo/gitosis-admin.git/hooks/post-update
root@<server>:/home/git/repositories/gitosis-admin.git# exit
#创建一个测试项目teamwork.git
ubuntu@<server>:/tmp/gitosis$ su - git
$ cd /data/repo
$ mkdir teamwork.git
$ cd teamwork.git
$ git init --bare
$ exit
在客户端<pc1>
#git权限管理本身也是通过一个git仓库来管理的, 将gitosis-admin.git复制clone下来
<pc1>:projects admin$ git clone git@<server>:gitosis-admin.git
<pc1>:repo admin$ cd gitosis-admin/
#将别的用户<pc2>的pub公钥加进来, 我是把它先copy到~/Downloads/下了
<pc1>:gitosis-admin admin$ cp ~/Downloads/id_rsa.pub ./keydir/<user2@pc2>.pub
#修改权限配置
<pc1>:gitosis-admin admin$ vim gitosis.conf
----------------------------------------
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = ubuntu@server user1@pc1
[group hello]
writable = teamwork
members = user1@pc1 user2@pc2
------------------------------------------
<pc1>:gitosis-admin admin$ git add .
<pc1>:gitosis-admin admin$ git commit -a -m "add my netbook user"
<pc1>:gitosis-admin admin$ git push origin master
<pc1>:repo admin$ mkdir teamwork-ori
<pc1>:repo admin$ cd teamwork-ori/
<pc1>:teamwork-ori admin$ git init
<pc1>:teamwork-ori admin$ vim README
<pc1>:teamwork-ori admin$ git add .
<pc1>:teamwork-ori admin$ git commit -a -m "initial version"
<pc1>:teamwork-ori admin$ git remote add origin git@<server>:teamwork.git
<pc1>:teamwork-ori admin$ git push origin master
然后从pc2的机器上,也就clone下来git仓库来使用了,很棒!
注意,中间如果遇到这样的错误,很可能是gitosis.conf配置的不对
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly
有可能是:
1. gitosis 中写的用户名,和keydir里面的key的名字没有完全对应上
2. 有的地方写错了,比如我把members写成了member,汗
[补充]:
1. 默认remote为master的配置方法:
$ git config branch.master.remote origin $ git config branch.master.merge refs/heads/master