Ubuntu下GIT服务器的安装与配置

 

Created Monday 30 January 2012

1. 安装
1.1 安装Git-Core:
sudo apt-get install git-core

1.2 安装 Gitosis
sudo apt-get install python-setuptools
mkdir ~/src
cd ~/src
git clone https://github.com/res0nat0r/gitosis.git

cd gitosis
sudo python setup.py install

1.3 增加名为Git的用户
sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git

1.4 上传公钥(如果没有,用 ssh-keygen -t rsa 生成)到Git服务器
本地客户端操作
scp .ssh/id_rsa.pub git@YOUR_SERVER:/home/git
(YOUR_SERVER换成你服务器IP或域名)
Git服务器操作
sudo -H -u git gitosis-init < /home/git/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

2. 配置
2.1 修改配置文件
git clone git@YOUR_SERVER:gitosis-admin.git

成功后,在本地将有一个gitosis-admin目录,里面有gitosis.conf,keydir。
编辑gitosis.conf,添加如下内容
[group rebill.info]
writable = rebill.info
members = rebill@rebill-laptop

然后,提交修改
git commit -a -m "created a new repository"
git push

2.2 新建Git项目
mkdir rebill.info
git init
git remote add origin git@YOUR_SERVER:rebill.info.git
git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master

2.3 添加Git成员
cd gitosis-admin
cp ~/user_a.pub keydir/
cp ~/user_b.pub keydir/
cp ~/user_c.pub keydir/
git add keydir/user_a.pub keydir/user_b.pub keydir/user_c.pub

修改gitosis.conf
[group mobile]
writable = android_project
members = user_a user_b

[group mobile_ro]
readonly = android_project
members = user_c

现在 user_c 可以克隆和获取更新,但 Gitosis 不会允许他向项目推送任何内容。
提交修改
git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey"
git push

这样,其它成员就可以获取代码了
git clone git@YOUR_SERVER:android_project.git

posted @ 2012-03-06 23:13  hopetribe  阅读(353)  评论(0编辑  收藏  举报