1.安装gitosis首先是获取gitosis(这里假设你已经安装过git):git clone git://github.com/res0nat0r/gitosis.git接下来安装gitosis:sudo python setup.py install 接下来添加用来管理仓库的用户,用户名任意,我们这里使用git:useradd gitMac用户在「系统偏好设置 » 用户与群组 」中添加。修改PATH,使git用户可以调用git:vi /home/git/.bashrcPATH=/usr/local/bin:/usr/local/git/bin:$PATH创建key pair,并拷贝public key到/tmp下,这样可以确保gitosis-init命令对其有读取权限:ssh-keygen -t rsacp ~/.ssh/id_rsa.pub /tmp/id_rsa.pub以git用户来执行gitosis-init命令:sudo -H -u git gitosis-init < /tmp/id_rsa.pub此时/home/git下增加了两个目录:gitosisrepositories其中gitosis是gitosis的根目录,repositories是仓库存放目录。如果出现以下错误:if install git from source, otherwise:raise child_exceptionOSError: [Errno 2] No such file or directory那么做个symlink:ln -s /usr/local/bin/git /usr/bin/git给脚本post-update赋予可执行权限:sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update2. 添加新仓库gitosis的管理是通过git来管理的,clone一下:git clone git@localhost:gitosis-admin.git cd gitosis-adminls -l-rw-r--r--  1 weizhifeng  staff  124  6 14 13:45 gitosis.confdrwxr-xr-x  3 weizhifeng  staff  102  6 14 13:46 keydirkeydir目录用来存放用户的public key(.pub文件),gitosis.conf为配置文件。看一下配置文件:cat gitosis.conf[gitosis][group gitosis-admin]    members = root@pc3    writable = gitosis-admin其中group代表一个组,writable是仓库名,members是此仓库的成员,可以有多个成员,用空格进行分割。添加一个新仓库:[group test]    members = root@pc3 pc2    writable = test把更改提交并push到git@localhost:gitosis-admin.git:git commit -a -m "添加新仓库test"git push在本地创建一个仓库,并push到git@localhost:test.git,gitosis会在/home/git/repositories自动创建test.git这个仓库:mkdir testcd test touch READMEgit initgit remote add origin git@localhost:test.gitgit push origin master3. 添加用户假设我们要添加的用户为pc2,那么需要创建key pair:ssh-keygen -t rsa假设生成的public key为~/.ssh/jeremy.pubcd gitosis-admin修改gitosis.conf,修改后为如下:[group test]members = root@pc3 pc2writable = test注意.pub文件名和你要在members中添加的用户名要完全一样。拷贝jeremy.pub到keydir中:cp ~/.ssh/pc2.pub keydir/把更改push到gitosis-admin.git:git commit -a -m "添加jeremy到test仓库"git push接下来把private key分发给pc2,然后他就可以从自己的机器上进行clone了:git clone git@SERVER_HOSTNAME:test.git如果出现以下错误:ERROR:gitosis.serve.main:Repository read access deniedfatal: The remote end hung up unexpectedly是因为使用了内容相同,名字不同的public key(.pub)。4.其他如果SSH使用的不是22端口,那么请如下修改:vi ~/.ssh/configHost myserver.comPort 2345     git分支:
git用户提权:
vim /etc/sudoers
添加:
Defaults visiblepw
git ALL=(ALL:ALL) ALL
在命令行执行:
将nginx用户添加到git组:
gpasswd -a nginx git
(未完)
 原文:https://www.cnblogs.com/uvwill/p/10986407.html