使用Gitosis搭建Git服务器

作者: JeremyWei | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://weizhifeng.net/build-git-server-with-gitosis.html
Git 1.安装gitosis
首先是获取gitosis(这里假设你已经安装过git): git clone git://github.com/res0nat0r/gitosis.git
接下来安装gitosis: sudo python setup.py install
如果出现以下错误: Traceback (most recent call last):
File "setup.py", line 2, in ?
from setuptools import setup, find_packages
ImportError: No module named setuptools
或者 -bash: python: command not found 那么你还需要安装python-setuptools: sudo yum install python-setuptools
接下来添加用来管理仓库的用户,用户名任意,我们这里使用git: useradd git
Mac用户在「系统偏好设置 » 用户与群组 」中添加。 修改PATH,使git用户可以调用git: vi /home/git/.bashrc
PATH=/usr/local/bin:/usr/local/git/bin:$PATH
创建key pair,并拷贝public key到/tmp下,这样可以确保gitosis-init命令对其有读取权限: ssh-keygen -t rsa
cp ~/.ssh/id_rsa.pub /tmp/id_rsa.pub
以git用户来执行gitosis-init命令: sudo -H -u git gitosis-init < /tmp/id_rsa.pub
此时/home/git下增加了两个目录: gitosis
repositories
其中gitosis是gitosis的根目录,repositories是仓库存放目录。 如果出现以下错误: if install git from source, otherwise:
raise child_exception
OSError: [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-update
2. 添加新仓库
gitosis的管理是通过git来管理的,clone一下: git clone git@localhost:gitosis-admin.git
如果出现以下错误: Cloning into gitosis-admin...
ssh: connect to host 192.168.1.30 port 22: Connection refused
fatal: The remote end hung up unexpectedly
那么确认当前机器openssh是否已经启动,Mac用户通过”系统偏好 -> 共享 -> 远程登录”进行设置。 cd gitosis-admin
ls -l
-rw-r--r-- 1 weizhifeng staff 124 6 14 13:45 gitosis.conf
drwxr-xr-x 3 weizhifeng staff 102 6 14 13:46 keydir
keydir目录用来存放用户的public key(.pub文件),gitosis.conf为配置文件。 看一下配置文件: cat gitosis.conf
[gitosis] [group gitosis-admin]
members = Mac
writable = gitosis-admin
其中group代表一个组,writable是仓库名,members是此仓库的成员,可以有多个成员,用空格进行分割。 添加一个新仓库: [group test]
members = Mac
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 test
cd test
touch README
git init
git remote add origin git@localhost:test.git
git push origin master
3. 添加用户
假设我们要添加的用户为jeremy,那么需要创建key pair: ssh-keygen -t rsa
假设生成的public key为~/.ssh/jeremy.pub cd gitosis-admin
修改gitosis.conf,修改后为如下: [group test]
members = Mac jeremy
writable = test
注意.pub文件名和你要在members中添加的用户名要完全一样。 拷贝jeremy.pub到keydir中: cp ~/.ssh/jeremy.pub keydir/
把更改push到gitosis-admin.git: git commit -a -m "添加jeremy到test仓库"
git push
接下来把private key分发给jeremy,然后他就可以从自己的机器上进行clone了: git clone git@SERVER_HOSTNAME:test.git
如果出现以下错误: ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly
是因为使用了内容相同,名字不同的public key(.pub)。 4.其他
如果SSH使用的不是22端口,那么请如下修改: vi ~/.ssh/config
Host myserver.com
Port 2345
5. 参考
http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way/
http://lukhnos.org/blog/en/archives/162/
http://blog.longwin.com.tw/2011/03/linux-gitosis-git-server-2011/

  

使用Gitosis搭建Git服务器的更多相关文章

  1. 用Gitosis搭建Git服务器(经典资料)

    该文档介绍了用Gitosis自己搭建Git服务器,文章来自于<Git权威指南>一书的第31章,讲述详细易懂易操作,是搭建Git服务器绝好资料! 下载地址:http://download.c ...

  2. Git学习笔记(10)——搭建Git服务器

    本文主要记录了Git服务器的搭建,以及一些其他的配置,和最后的小总结. Git远程仓库服务器 其实远程仓库和本地仓库没啥不同,远程仓库只是每天24小时开机为大家服务,所以叫做服务器.我们完全可以把自己 ...

  3. 如何在服务器上搭建git服务器

    参考文章: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770 ...

  4. CentOS 6.4 搭建git 服务器

    CentOS 6.4 搭建git 服务器 (2013-11-22 19:04:09)转载▼ 标签: it 分类: Linux 此文件是依据markdown所编写,更好效果参见本人github的文档ht ...

  5. CentOs上搭建git服务器

    CentOs上搭建git服务器 首先安装setuptools wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0 ...

  6. 自定义Git之搭建Git服务器

    在远程仓库一节中,我们讲了远程仓库实际上和本地仓库没啥不同,纯粹为了7x24小时开机并交换大家的修改. GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业公司来说,既不想 ...

  7. 轻松搭建Git服务器(Ubuntu)

    搭建Git服务器 在远程仓库节中,我们讲了远程仓库实际上和本地仓库没啥不同,纯粹为了7x24小时开机并交换大家的修改. GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业 ...

  8. CentOS搭建Git服务器及权限管理

    声明:本教程,仅作为配置的记录,细节不展开,需要您有一点linux的命令基础,仅作为配置参考. 1. 系统环境 系统: Linux:CentOS 7.2 64位 由于CentOS已经内置了OpenSS ...

  9. Ubuntu16 搭建Git 服务器

    刚入职一个月左右,昨晚公司给培训了SVN和Git的使用.之前在研究生期间,和导师做项目就一直使用git做版本管理.想起研究生有一段时间,git总出错(秘钥都不好使了,只有某个机器生成的rsa key ...

随机推荐

  1. yourphp 的 ThinkTemplate.class.php与ContentReplaceBehavior.class.php

    ThinkTemplate.class.php :去掉版权(针对html代码) ContentReplaceBehavior.class.php:一些默认标签的路劲,如:__PUBLIC__,../P ...

  2. union联合体使用详解

    1.联合体联合体(union)与结构体(struct)有一些相似之处.但两者有本质上的不同.在结构体中,各成员有各自的内存空间, 一个结构变量的总长度是各成员长度之和.而在联合体中,各成员共享一段内存 ...

  3. Python之路【第六篇】:面向对象编程相关

    判断类与对象关系 isinstance(obj, cls)  判断对象obj是否是由cls类创建的 #!/usr/bin/env python #-*- coding:utf-8 -*- class ...

  4. Linux动态库的编译与使用 转载

    http://hi.baidu.com/linuxlife/blog/item/0d3e302ae2384d3a5343c1b1.html Linux下的动态库以.so为后缀,我也是初次在Linux下 ...

  5. css3实现渐变的iPhone滑动解锁效果

    先贴代码 <!DOCTYPE html> <html> <head> <style> p{ width:50%; margin:0 auto; line ...

  6. windows下vmware10.0 安装centos7

    centos7.0-1506, 1511, 是指2015年, 06月份, 11月份. 这是rhel ubuntu发布新版本的时间. centos7.0 只提供了64位的系统下载: x86_64: we ...

  7. oracle 中的round()函数、null值,rownum

    round()函数:四舍五入函数 传回一个数值,该数值按照指定精度进行四舍五入运算的结果. 语法:round(number[,decimals]) Number:待处理的函数 Decimals:精度, ...

  8. 响应式Web初级入门

    本文来自我的前端博客,原文地址:http://www.hacke2.cn/about-responsive/ 跨终端时代的到来 当你乘坐各种交通工具(公交.地铁.轻轨.火车)时你会发现,人们都个个低下 ...

  9. 大熊君大话NodeJS之------Net模块

    一,开篇分析 从今天开始,我们来深入具体的模块学习,这篇文章是这个系列(大熊君大话NodeJS)文章的第三篇,前两篇主要是以理论为主,相信大家在前两篇的学习中, 对NodeJS也有一个基本的认识,没事 ...

  10. linux压缩排除

    tar -zcvf www/la.tar.gz --exclude=www/uploadfile --exclude=www/databases --exclude=www/web_logs www ...