Git server 搭建步骤 on Linux (二)


7.     Generate rsa key 

You may create rsa key on you PC which will manager git(Windows OS need setup msysgit). Here we user the work user (the same pc with gitserver) to manager git.

A.     Generate rsa key:

work@work:~$ ssh-keygen –t rsa

Follow the default hint “Enter”. It will create file :

ü  /home/work/.ssh/id_rsa (私钥)

ü  /home/work/.ssh/id_rsa.pub (公钥)

B.     Upload rsa pub key to gitserver

Upload rsa pub key to gitserver /tmp:

work@work:~$ scp .ssh/id_rsa.pub /tmp

PS:如果git管理员跟git server不同pc话要用scp .ssh/id_rsa.pub git@10.66.2.80:/tmp

 

8.     initialize gitosis 

work@work:~$ cd /tmp

work@work:/tmp$ sudo chmod 777 id_rsa.pub

work@work:/tmp$ sudo –H –u git gitosis-init < id_rsa.pub

git is user name we create in Step 6. It will create two folders in /home/git: gitosis and repositories. gitosis-admin.git的仓库 in repositories.

 Chmod to allow user clone gitosis-admin.git:

work@work:~$ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

Currently gitosis setup finish(git server establishment finish). 

9.     Test

A.     Create TEST.git 

Create new folder anywhere(end with .git). Here we create /home/git/git_repo/TEST.git with git user

work@work:~$ su git

$ mkdir TEST.git

$ cd TEST.git

$ sudo git –bare init

$ exit

B.    Initialize TEST.git  version 

Now it is one empty git 仓库,you can add something here with git admistrator user to initialize one version:

work@work:~$ mkdir TEST

work@work:~$ cd TEST

work@work:/TEST$ git init

work@work:/TEST$ echo “test info” > hello.txt

work@work:/TEST$ git add

work@work:/TEST$ git commit –am “initialize version”

work@work:/TEST$ git remote add origin git@10.66.2.80:TEST.git

work@work:/TEST$ git push origin master

Remark: 

1. You must do this with git user(we create in step 6)

2. You must user –bare for the initialization (two ‘-‘ before bare)

3. New folder must end with .git

C.    modify visit authority 

We need to modify gitosis config file to allow user to operate git project. 

i.          Create folder to save gitosis-admin仓库的目录

work@work:~$ mkdir gitosis-admin

work@work:~$ cd gitosis-admin

work@work:~$ git clone 

You might change “10.66.2.80” to your own ip addr. 如果clone失败可以试下运行 ssh-add:

work@work:~$ ssh-add

Now gitosis-admin的仓库clone到本地了。进入gitosis-admin仓库目录,会看到:

ü  gitosis.conf

gitosis.conf文件用于配置用户和权限,打开gitosis.conf文件,内容为:

[group gitosis-admin]

Writable = gitosis-admin

Members = git管理员账户名@git管理员机器名

这个就是管理组的权限,members中的用户名就是之前上传的公钥里面的用户名

ü  /keydir/xxx.pub

其中xxx的格式为git管理员账户名@git管理员机器名(work@work)。

/keydir目录下是所有用户的公钥

ii.          添加git普通用户访问权限

下面以用户one为例(one PC机器名为onepc):

1)         Copy one pc上生成的公钥到keydir目录下

2)         gitosis.conf修改为:(红色部分)

[gitosis]

Gitweb =yes   

 

[group gitosis-admin]

Writable = gitosis-admin

Members = git管理员账户名@git管理员机器名

 

[group TEST]

Writable = TEST

Members = git管理员账户名@git管理员机器名 one@onepc

其中gitweb=yes 表示启用对gitweb的支持。添加了one用户对TEST仓库的写权限,同时创建了一个叫TEST的组。

3)         将修改push到服务器:

work@work:~$ git commit –a –m “add user one to modify TEST”

work@work:~$ git push

Currently git server authority set ok and also git server establishment also finish. Team member can now operate git 仓库. 

D.    普通用户operate git仓库入门

下面以上面提到的one用户为例:

one@onepc:~$ mkdir TEST

one@onepc:~$ cd TEST

one@onepc:/TEST$ git clone 

现在TEST就clone下来了,可以对TEST进行修改了

Remark:git clone时“”后面要直接写创建的项目名称,不需要其他的路径

 Reference 

[1]     Pro Githttp://progit.org/book/zh/index.html

[2]     git使用初探

http://archive.cnblogs.com/a/1911799/

[3]     Ubuntu上搭建

http://wenku.baidu.com/view/a117750c4a7302768e9939e7.htmlhttp://xxw8393.blog.163.com/blog/static/3725683420105224424689/

http://blog.csdn.net/ice520301/archive/2011/01/15/6142503.aspx

[4]     Windows,Linux搭建

http://www.doc88.com/p-67839116264.html

[5]     Windows上搭建Git服务器  

http://blog.csdn.net/kechen/archive/2010/11/24/6032398.aspx

[6]     SSH+Git Server on Windows

http://blog.csdn.net/Mr_Von/archive/2010/01/15/5192502.aspx

[7]     用开源ASP.NET MVC程序Bonobo Git Server搭建Git服务器http://www.cnblogs.com/dudu/archive/2011/06/24/git_on_windows.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值