`
wbj0110
  • 浏览: 1587400 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

Git 服务器 Gitosis 架设指南

阅读更多

Git是非常著名的分布式版本控制系统。
Gitosis则是方便通过Git与ssh架设中央服务器的软件。这篇文章的安装流程写得很明了,但使用中还是遇到了些许问题,本文算是该流程的补充。如果打算通过Gitosis架设服务器通过本文或许可以少走不少弯路。

 

一、架设步骤

 

1. 下载并安装python setuptools

sudo apt-get install python-setuptools

2. 下载并安装gitosis

cd ~/src
git clone git://eagain.net/gitosis.git
cd gitosis
python setup.py install

3. 添加用户git

 

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git

 

4. 生成本机密钥

切换到个人机,如果已有~/.ssh/id_rsa.pub略过此步
ssh-keygen -t rsa

5. 上传密钥到服务器临时目录

scp ~/.ssh/id_rsa.pub 用户名@主机:/tmp

6. 初使化gitosis

切回到服务器
sudo -H -u git gitosis-init < /tmp/id_rsa.pub

7. 修改post-update权限

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

8. clone gitosis管理平台

git clone git@主机名:gitosis-admin.git
cd gitosis-admin

9. 安装完成

通过修改gitosis-admin管理gitosis用户权限
添加公密到keydir,添加用户
修改完后commit,push到中服务器即可完成仓库权限的相关操作。

二、实例

目标:添加用户 john 和仓库 foo 到gitosis,并和管理员miao合作管理

1. 用户john添加并发送id_rsa.pub给miao

 

john:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/john/.ssh/id_rsa):
Created directory '/home/john/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/john/.ssh/id_rsa.
Your public key has been saved in /home/john/.ssh/id_rsa.pub.
john:~$ cp /home/john/.ssh/id_rsa.pub /tmp

 

2. gitosis管理员miao分配john权限

 

miao:~$ cd ~/projects
git clone git@192.168.1.115:gitosis-admin
cd gitosis-admin
cat gitosis.conf
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = miao@u32-192-168-1-110
ls keydir/
miao@u32-192-168-1-110.pub
cp /tmp/id_rsa.pub keydir/john.pub
vi gitosis.conf
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = miao@u32-192-168-1-110

[group foo]
writable = foo
members = miao@u32-192-168-1-110 john
git add .
git commit -am "add member john and project foo"
git push

 

3. 用户 miao 添加项目foo

 

miao:~$ cd ~/projects
mkdir foo
cd foo
git init
touch hello.txt
git add hello.txt
git commit -am 'first commit'
git remote add origin git@192.168.1.115:foo.git
git push origin master

 

4. 用户 john clone Foo并修改hello.txt

 

john:~$ git clone git@192.168.1.115:foo.git
cd foo
ls
date > hello.txt
git commit -am 'add time to hello.txt' && git push

 

5. 用户 miao pull Foo

 

miao:~/projects/foo$ vi .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = git@192.168.1.115:foo.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
git pull

 

三、常见问题

首先确定 /home/git/repositories/gitosis-admin.git/hooks/post-update 为可执行即属性为 0755

1. git操作需要输入密码

 

原因
公密未找到
解决
上传id_pub.rsa到keydir并改为'gitosis帐号.pub'形式,如miao.pub。扩展名.pub不可省略

 

2. ERROR:gitosis.serve.main:Repository read access denied

 

原因
gitosis.conf中的members与keydir中的用户名不一致,如gitosis中的members = foo@bar,但keydir中的公密名却叫foo.pub
解决
使keydir的名称与gitosis中members所指的名称一致。
改为members = foo 或 公密名称改为foo@bar.pub

来自:http://www.open-open.com/lib/view/open1349849744275.html

分享到:
评论

相关推荐

    Git权威指南

    第5篇介绍了git服务器的架设,首先讲解了http协议、git协议、ssh协议的使用,然后讲解了gitolite、gitosis、gerrit等服务器的架设方法,最后还讲解了git版本库的托管。第6篇介绍了版本库的迁移,包括如何从cvs、svn...

    Git权威指南PDF完整版

    第5篇 搭建Git服务器 第27章 使用 HTTP 协议/ 398 27.1 哑传输协议/ 398 27.2 智能 HTTP 协议/ 400 27.3 Gitweb 服务器/ 401 27.3.1 Gitweb的安装/ 402 27.3.2 Gitweb的配置/ 403 27.3.3 版本库的 Gitweb 相关设置/ ...

    Git权威指南【样张】

    第5篇介绍了git服务器的架设,首先讲解了http协议、git协议、ssh协议的使用,然后讲解了gitolite、gitosis、gerrit等服务器的架设方法,最后还讲解了git版本库的托管。第6篇介绍了版本库的迁移,包括如何从cvs、svn...

    Git Pro中文版--高清pdf

    服务器部署可以通过转移仓库目录、小型安装、生成SSH公钥、架设服务器、提供公共访问和网页界面、权限管理、Git进程和托管服务等方式进行。 GitWeb是一种网页界面,可以查看Git仓库的界面;Gitosis是一个权限管理...

    git学习资料

    如何在服务器上部署Git,包括生成SSH公钥,架设服务器,公共访问,网页界面GitWeb,权限管理器Gitosis等。而在Git托管服务方面,GitHub是大家最为熟知的一个平台,如何在GitHub上建立账户、建立新仓库、导入项目,...

    git详解-PDF

    - **架设服务器**:包括安装必要的软件和服务。 - **公共访问**:配置服务器以允许外部用户访问。 - **GitWeb**:一个基于PHP的网页前端,用于浏览Git仓库的内容。 - **Gitosis**:用于管理多个Git仓库的工具。 - **...

    版本工具git教程

    在服务器部署Git部分,教程讲解了如何将纯目录转移到服务器,如何通过SSH连接进行小型安装,如何生成SSH公钥,架设服务器,公共访问,网页界面GitWeb的设置,权限管理器Gitosis的配置,以及Git进程。 Git托管服务...

    Pro Git中文版本PDF档

    部署Git服务器时,可以使用多种方法,包括将纯目录转移到服务器、架设服务器、使用权限管理器Gitosis等。此外,还有Git托管服务,比如GitHub,它提供了网页界面和对项目的管理功能。 分布式工作流程是Git的核心特点...

    Git 实用中文版参考手册

    包括了使用不同协议(如本地协议、SSH协议、Git协议和HTTP/S协议)进行仓库访问,以及如何设置SSH公钥、架设服务器、设置公共访问、使用GitWeb和Gitosis等权限管理器。还有Git托管服务,如GitHub的介绍,包括创建...

    git使用操作中文手册

    如何将现有的纯文件夹转移到Git服务器。 - **4.2.2 小型安装** 适用于小型项目的安装指南。 - **4.3 生成SSH公钥** 生成用于认证的SSH公钥。 - **4.4 架设服务器** 设计和搭建Git服务器的步骤。 **4.5 公共...

Global site tag (gtag.js) - Google Analytics