用gitosis搭建git server

参考链接http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

1.安装gitosis
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install
(或者直接用包管理器apt-get 之类的安装)
注:需要python-setuptools
2.建议使用独立的账号来分配git权限。
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git
3.初始化设置gitosis
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
id_rsa.pub是git server管理员的公钥
之后的步骤可以不用在server上操作了。可以在其他电脑上进行了。用git本身来管理gitosis
git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
gitosis-admin目录中就两个东西,配置文件和密钥目录
gitosis.conf
keydir/

新建git库 newrepo。在gitosis.conf加入这行
[group newrepo]
members = test
writable = newrepo

用户test对newrepo有commit权限
下面命令建立newrepo库
mkdir newrepo
cd newrepo
git init
git remote add origin git@YOUR_SERVER_HOSTNAME:newrepo.git
# do some work, git add and commit files
git push origin master:refs/heads/master
增加用户只需要把新用户的公钥pub文件放到gitosis-admin下面的keydir中即可
示例:
cd gitosis-admin
cp ~/alice.pub keydir/
cp ~/bob.pub keydir/
git add keydir/alice.pub keydir/bob.pub

gitosis.conf changes:
[group myteam]
- members = jdoe
+ members = jdoe alice bob
writable = free_monkey
Commit and push:
git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey"
git push

用git daemon 提供public访问权限
sudo -u git git daemon --base-path=/home/git/repositories/ --export-all

Leave a Reply

Your email address will not be published.


*