首先安装setuptools
- wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
- tar zxvf setuptools-0.6c11.tar.gz
- cd setuptools-0.6c11
- python setup.py build
- python setup.py install
在服务器(CentOs)上首先安装git软件
- yum insatll git
安装gitosis
- git clone git://github.com/res0nat0r/gitosis.git
- cd gitosis
- python setup.py install
添加用户git
sudo useradd -r -s /bin/sh -c 'git version control' -d /home/git git
设置权限
mkdir -p /home/git
chown git:git /home/git
ssh登陆验证
- cat kailuzhe_rsa.pub >> authorized_keys authorized_keys存在,追加
- mv kailuzhe_rsa.pub authorized_key authorized_keys不存在,改名
生成公钥
- ssh-keygen -t rsa
上传公钥
- scp ~/.ssh/id_rsa.pub USER@YOUR_SERVER:/tmp
在服务端生成管理库
- sudo -H -u git gitosis-init < /tmp/id_rsa.pub
看到如下提示说明安装成功
Initialized empty Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/
修改上传权限
- chmod 755 /var/spool/gitosis/repositories/gitosis-admin.git/hooks/post-update
同步配置文件
- git clone git+ssh://git@118.123.16.30:22000/gitosis-admin.git
创建新的repositories
打开gitosis.conf文件,你将看到
[group gitosis-admin]
writable = gitosis-admin
members = nasa127@localhost
这个是管理组的权限,members中的用户名就是刚才上传的公钥里面的用户名。 在这个文件后面加入:
[group myteam]
members = nasa127@localhost
writable = diablo3_spider
这里你定义了一个叫myteam的组,授予nasa127@localhost这个用户写“diablo3_spider”这个repo的权限
git commit -a -m "Allow nasa write access to diablo3_spider"
git push
上面的操作就更新了服务端的权限。 下面就开始创建diablo3_spider的repo
mkdir diablo3_spider
cd diablo3_spider
git init
随便加一些文件提交代码:
git remote add origin git@YOUR_SERVER_HOSTNAME:diablo3_spider.git
git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master
接下来,可以增加成员的公钥到系统中了
cd gitosis-admin
cp ~/Administrator@SUNPX-PC.pub keydir/
cp ~/tongzhongqian@localhost.pub keydir/
git add keydir/Administrator@SUNPX-PC.pub keydir/tongzhongqian@localhost.pub
修改gitosis.conf
[group fractalist]
members = nasa127@localhost Administrator@SUNPX-PC tongzhongqian@localhost
writable = GTFund-iPad
提交修改:
git commit -a -m "Granted sunpx and qtz commit rights to diablo3_spider"
git push
其它成员就可以获取代码了
git clone git@YOUR_SERVER:diablo3_spider.git
其他
对Git设置端口号
git+ssh://git@YOUR_SERVER:PORT/GTFund-iPad.git
git remote add origin git+ssh://git@YOUR_SERVER:PORT/GTFund-iPad.git
参考文档
- http://blog.prosight.me/index.php/2009/07/271
- http://blog.chinaunix.net/uid-26337130-id-3027600.html
- https://github.com/res0nat0r/gitosis#using-gitweb
- http://www.jiangmiao.org/blog/1600.html
- http://hi.baidu.com/unspace/blog/item/81cef0d33db0f3c0a9ec9ab0.html
- http://code.google.com/p/tortoisegit/