git gitosis could not read from remote repository

[摘要]之前一直使用gitlab来管理git代码仓库,纵然gitlab搭建相对繁琐(ruby的依赖关系我也是醉了),但是gitlab文档比较成熟,也还算容易。这两天使用了简化一些的git,使用gitosis搭建了一套git环境,虽然没有管理界面,不过几经周折终于算是能用了,这里主要是列出几个搭建和使用过程中的坑:

1. 用户公钥,一定要用.pub结尾,放到gitosis-admin/keydir目录中,push之后会在git服务器上将pubkey加到/home/git/.ssh/authorized_keys文件中。

2. 项目创建后无法push
简要列一下我创建新项目的过程:
比如创建一个新的repo,名字为:test-ios:

$ mkdir test-ios
$ cd test-ios/
$ git init
Initialized empty Git repository in /Users/sudops/docs/git-repo/test-ios/.git/

$ git commit -m "create new repo"
[master (root-commit) 84e4842] create new repo
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README

$ git remote add origin git@sudops.com:test-ios.git
$ git push origin master
ERROR:gitosis.serve.main:Repository read access denied
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

在push的时候有如下错误:
ERROR:gitosis.serve.main:Repository read access denied
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

找了半天原因,一开始以为是pub key的问题,后来怀疑是默认git用户的问题,不过最终发现还是是项目的权限问题:
除了gitosis-admin的repo可以push之外,对于其他的repo正确的配置应为:

$ cat gitosis-admin/gitosis.conf 
[group gitosis-admin]
writable = gitosis-admin sudops_p1 sudops_p1
members = admin@sudops.com user1@sudops.com

[group git-test]
writable = git-test
members = admin@sudops.com user1@sudops.com

而不是:

$ cat gitosis-admin/gitosis.conf 
[group gitosis-admin]
writable = gitosis-admin sudops_p1 sudops_p1
members = admin@sudops.com user1@sudops.com

[group sudops_p1]
writable = sudops_p1
members = admin@sudops.com

[group sudops_p2]
writable = sudops_p2
members = admin@sudops.com

困扰一下午的问题终于解决,希望对大家在遇到此类问题搜到这篇文章的时候能够更快解决问题,减少时间的浪费。