使用gitosis来配置管理git服务器端
by Elton on 七.21, 2009, under Linux
1. 安装git
1 | emerge -av dev-util/git |
2.安装gitosis
git环境默认是可以直接使用的,但需要为每个成员开ssh权限帐号,且各个仓库之间的交叉权限管理很麻烦,所以需要使用gitosis, 它无需为每个开发人员开设ssh帐号,安全方便。
1 | emerge -av gitosis |
如果提示这个包被mask了,需要编辑/etc/portage/package.keywords文件,在里面加入
1 | dev-util/gitosis ~amd64 |
3.生成公钥
在客户端使用
1 | ssh-keygen -t rsa |
来生成ssh的key,注意你的主机名需要是全部英文字符,不能有下划线或者.之类的特殊字符,否则后面在服务端生成版本库的时候会报错。
4.上传公钥
从客户端把刚刚生成的公钥上传到服务器上。
1 | scp ~/.ssh/id_rsa.pub USER@YOUR_SERVER:/tmp |
5.在服务端生成管理库
1 | sudo -H -u git gitosis-init < /tmp/id_rsa.pub |
成功的话,你将看到类似下面的提示:
1 2 | Initialized empty Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/ |
设置post-update脚本权限
1 | chmod 755 /var/spool/gitosis/repositories/gitosis-admin.git/hooks/post-update |
至此,服务端配置已经完成。
6.同步配置文件
gitosis本身就是一个git库,所以管理起来非常方便。下面在客户端同步gitosis管理库
1 2 | git clone git@YOUR_SERVER:gitosis-admin.git cd gitosis-admin |
你将看到以下文件
1 2 | -rw-r--r-- 1 garry garry 104 Nov 13 05:43 gitosis.conf drwxr-xr-x 3 garry garry 102 Nov 13 05:43 keydir/ |
gitosis.conf是gitosis的配置文件,用于配置用户和权限
keydir/是所有组成员的公钥
我们可以在本地修改配置更改权限,然后push到服务端后,服务器端就立刻生效
7.创建新的repositories
打开gitosis.conf文件,你将看到
1 2 3 | [group gitosis-admin] writable = gitosis-admin members = elton@macbook |
这个是管理组的权限,members中的用户名就是刚才上传的公钥里面的用户名。
在这个文件后面加入:
1 2 3 | [group myteam] members = elton@macbook writable = free_monkey |
这里你定义了一个叫myteam的组,授予elton@macbook这个用户写“free_monkey”这个repo的权限
1 2 | git commit -a -m "Allow elton write access to free_monkey" git push |
上面的操作就更新了服务端的权限。
下面就开始创建free_monkey的repo
1 2 3 | mkdir free_monkey cd free_monkey git init |
创建 .gitignore 文件,用于忽略某些不需要进行代码管理的内容,如rails的应用可能如下:
1 2 3 4 5 | .DS_Store log/*.log tmp/**/* config/database.yml db/*.sqlite3 |
提交代码:
1 2 3 4 5 | git remote add origin git@YOUR_SERVER_HOSTNAME:free_monkey.git git add . git commit -a -m "initial import" git push origin master:refs/heads/master |
接下来,可以增加成员的公钥到系统中了
1 2 3 4 | cd gitosis-admin cp ~/alice.pub keydir/ cp ~/bob.pub keydir/ git add keydir/alice.pub keydir/bob.pub |
修改gitosis.conf
1 2 3 4 | [group myteam] - members = jdoe + members = jdoe alice bob writable = free_monkey |
提交修改:
1 2 | git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey" git push |
其它成员就可以获取代码了
1 | git clone git@YOUR_SERVER:free_monkey.git |
参考:
Hosting Git repositories, The Easy (and Secure) Way
56 Comments for this entry
2 Trackbacks / Pingbacks for this entry
-
Linux 使用 Gitosis 架設 Git Server | Tsung's Blog
三月 21st, 2011 on 01:30[...] 使用 gitosis 來配置管理 git 服務器端 [...]
-
Git使用相关资料 | | Loning's blogLoning's blog
五月 12th, 2011 on 19:53[...] 关于gitosis的配置问题可以参考这篇博文:http://blog.prosight.me/index.php/2009/07/271 This entry was posted in 技术文章 and tagged Add Key, git, SSH. Bookmark the permalink. ← 支付宝的客服很给力嘛,网站即时到帐在线签约今天终于搞定了~ [...]



一月 6th, 2010 on 10:20
博主:
请问:gitosis本身就是一个git库,那么我新建的一个工程,是导入gitosis这个git库,还是另外新建一个git库,然后进行导入?
如果是前者,我操作的时候,怎么老是提示没有新建的那个库?
如何是后者,gitosis和它好像没有关系啊?怎么能控制权限?
谢谢
一月 18th, 2010 on 05:22
Nice post mate
一月 20th, 2010 on 07:17
Nice post mate
一月 31st, 2010 on 19:28
Hello i am so delighted I found your blog, I really found you by mistake, while I was searching Yahoo for something else, Anyway I am here now and would just like to say thanks for a tremendous blog posting and a all round interesting blog (I also love the theme/design), I do not have time to read it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read more,
三月 26th, 2010 on 22:21
Just thought i would comment and say neat design, did you code it yourself? Looks great. If you wantto exchange the links with us please let me know.
三月 30th, 2010 on 11:04
I love design and code for website, but this layout is provided by wordpress. Yes, It’s my pleasure to exchange link with you. Thanks
五月 18th, 2010 on 11:59
Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I’m more of a visual learner,I found that to be more helpful well let me know how it turns out! I love what you guys are always up too. Such clever work and reporting! Keep up the great works guys I’ve added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.
六月 2nd, 2010 on 16:20
Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also…
七月 24th, 2010 on 16:18
Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
七月 27th, 2010 on 22:58
I am not really sure if best practices have emerged around things like that, but I am sure that your great job is clearly identified. I was wondering if you offer any subscription to your RSS feeds as I would be very interested.
七月 28th, 2010 on 11:56
I am not really sure if best practices have emerged around things like that, but I am sure that your great job is clearly identified. I was wondering if you offer any subscription to your RSS feeds as I would be very interested.
七月 29th, 2010 on 13:21
I tried to subscribe to your rss feed, but had a problem adding it to google reader. Could you please check this out.
七月 29th, 2010 on 14:58
I have checked it. But I can subscribe my rss feed by using google reader. Could you give me more information?
七月 29th, 2010 on 19:20
I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful. . . .
七月 30th, 2010 on 12:51
I am just making a blog related to this. If you allow, I would like to use some of your content. And with full refernce of course. Thanks in advance.
七月 30th, 2010 on 12:51
Excellent post I must say.. Simple but yet interesting and engaging.. Keep up the awesome work!
七月 30th, 2010 on 16:10
wow, awesome post, I was wondering how to cure acne naturally. and found your site by bing, many userful stuff here, now i have got some idea. bookmarked and also signed up your rss. keep us updated.
八月 2nd, 2010 on 12:24
Wow, very interesting article. It’s funny how history can be twisted in so many different ways. These photos certainly give us clues, but I guess we’ll never know the true story. . . .
八月 2nd, 2010 on 12:26
Wow, very interesting article. It’s funny how history can be twisted in so many different ways. These photos certainly give us clues, but I guess we’ll never know the true story. . . .
八月 3rd, 2010 on 15:54
thanks for the post. I am very happy to read this post. . . . .
八月 5th, 2010 on 03:11
Hey – nice blog, just looking around some blogs, seems a pretty nice platform you are using. I’m currently using WordPress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?
八月 9th, 2010 on 02:56
Great post, thanks. A good quick read.
八月 11th, 2010 on 03:11
Adding to my bookmarks thanks. Do you have a RSS feed?
八月 13th, 2010 on 21:13
Bookmarking now thanks, found you through Google.
八月 16th, 2010 on 01:22
I can see that you are an expert at your field! I am starting a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.
八月 16th, 2010 on 18:27
Have found your web page. My pal mentioned it to me before, yet never got around to checking it out until now. I must express, I’m floored. I really enjoyed reading through your posts and will absolutely be back to get more.
八月 18th, 2010 on 14:19
Simply want to say your article is as tonishing. The clearness in your post is simply spectacular and i can assume you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.
八月 20th, 2010 on 04:48
I thought it was going to be some boring old site, but I’m glad I visited. I will post a link to this page on my blog. I believe my visitors will find that very useful.
八月 20th, 2010 on 04:55
I enjoyed reading this, You must have a Facebook group for your site?
八月 22nd, 2010 on 03:53
The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!
八月 25th, 2010 on 01:40
I enjoyed reading this, You must have a Facebook group for your site?
八月 25th, 2010 on 20:28
Really great, practicly explained and useful Recommendations.
八月 27th, 2010 on 01:43
I have to admit I don’t always agree with you, but in this case you really hit the nail on point.
八月 27th, 2010 on 15:43
This is my first time visiting your site. I do envy you since you seem to get a lot more comments then I do. Do you have any secret tips on how I can get more comments or do I just have to be paitent? Anyway, keep up the good work.
八月 27th, 2010 on 16:55
I believe it does assist relieve tension. It calms the mind and releases some of the fear and anxiousness.
九月 2nd, 2010 on 14:58
This was a great post, I hope you will write some more of these in the future….
九月 3rd, 2010 on 18:27
Thank you very much. This really helped me with my work. I appreciate your help. Thanks a lot.
九月 5th, 2010 on 18:02
Spotted a link to this post over on Stumbleupon. Thanks for posting it. I’m sure I’ll be back one day.
九月 5th, 2010 on 18:50
This is a subject near to my heart thanks, needed some more images maybe.
九月 6th, 2010 on 04:55
Wow this definitely takes me back, a good quick read.
九月 6th, 2010 on 08:55
It’s awesome how much decent information you can find these days on the internet. Thank you for the post good Sir.
九月 7th, 2010 on 08:29
Amazing post. You know I just got back together with my ex and this blog just made me even happier.
九月 7th, 2010 on 14:54
Good article, Every and Every Stage is Excellent enough.Many thanks for sharing with us your wisdom.
十月 14th, 2010 on 14:26
I think that is an interesting point, it made me think a bit. Thanks for sparking my thinking cap. Sometimes I get so much in a rut that I just feel like a record.
十月 14th, 2010 on 15:09
Thanks for this
十月 15th, 2010 on 04:54
Good to know, thanks for the usefull knowledge.I just love it!
十月 15th, 2010 on 05:48
A tomfool may soul country over a peacock but instead modify the laze
十月 15th, 2010 on 12:11
I really take pleasure in your blog but you should look at the punctuation on some of your stories. Some of them are packed with spelling problems and I still find it very bothersome to tell the truth nonetheless I probably will come back again.
十月 15th, 2010 on 16:17
i don’t have an opinion on this issue
十月 15th, 2010 on 16:41
Awesome website! You’ve a excellent website, absolutely the best Ive read so far. I will be looking forward to your next reads.Thanks again.
十月 15th, 2010 on 23:27
I just wanted to comment and say that I really enjoyed reading your blog post here. It was very informative and I also digg the way you write! Keep it up and I’ll be back to read more in the future
十月 16th, 2010 on 00:23
That was very imformative. Thanks for all of the information.
十月 16th, 2010 on 04:41
This site is great! i visit here everyday.
十月 16th, 2010 on 22:47
I love the writing relevancy of your website and it will a nice-looking decent work of presenting the info.
十月 16th, 2010 on 23:07
I usually don’t reply on web pages nevertheless you contain a few fine readable article.
十月 22nd, 2010 on 02:40
Where can I get this particular system?