Set up git server on ubuntu using ssh protocol(已经测试可以)

Set up git server on ubuntu using ssh protocol

0.     basis

OSubuntulinux

Use X.X.X.X as git server;

Use my virtualbox VM host1 as git client. Host1 has twousers: one is jwx (as git admin), and the othe is normal user.

 

Install openssh in both server and clent hosts. Indefault, ubuntu has installed openssh.

 

1.     Gitclient

apt-get update

apt-get install git

 

create a user in client

git config --global user.name “user”

git config –global user.email “user@git.com

 

2.   Git server

(1)    install git

root@server: #  apt-getupdate

root@server: # apt-getinstall git

       After installation, you can use git –versionto check the git version.

 

(2)    Add newuser named “git”

root@server: #  Useradd–m git

root@server: #  Passwdgit

       The git user will be the admin formanaging git repositories and users access.

 

(3)    Create storing place for repositories

root@server: #  Mkdir/home/repo

 

modify the access for thisdirectory

root@server: # chown git:git /home/repo

 

change to git user and create a soft linkabout git repos

root@server:/tmp#   su git

git@server:/tmp# ln –s /home/repo/home/git/repositories

 

(4)    Use gitosis to manage users of git

      We must create a user in order to use git. 

root@server: # git config –global user.name “root”

root@server: # git config –global user.emailroot@git.com

 

Install python-setuptools for setting upgitosis.

root@server: # apt-get install python-setuptools

 

gain gitosis package from git.

root@server:/tmp# git clonehttps://github.com/res0nat0r/gitosis.git

 

Install gitosis

root@server:/tmp# cd gitosis

root@server:/tmp# python setup.py install

 

(5)    If usejwx user on client host1 as git admin, config ssh public key

Login jwx on host1.

jwx@ubunt-host1: ~$ ssh-keygen –t rsa

copy this id_rsa.pub to the directory /tmp of gitserver X.X.X.X.

 jwx@ubunt-host1:~$  scp .ssh/id_rsa.pub git@X.X.X.X:/tmp 

       change to git server, and run gitosisusing above ssh key.

root@server:/tmp# cd gitosis

root@server:/tmp/gitosis# sudo –H git gitosis-init <  /tmp/id_rsa.pub

 

  gitosis use git repo “gitosis-admin.git” to manage configure files. Sowe must add “X” privilege to a certain file.

root@server:/home/git# chmod 755 /home/repo/gitosis-admin.git/hooks/ post-update

 

(6)    Here, we want to share ourproject “bmc”, create this null repo.

root@server:/home/git$  su – git

git@server: cd /home/bmc

git@server:/home/bmc$ mkdir teamwork.git

git@server:/home/bmc/teamwork.git $ git init --bare

 

      This repo is null, and null repo could not be cloned, so we must let auser to place a init version into this “teamwork.git”repo.

 

(7)    Configure users’ access throughgitosis-admin.git

Login jwx (git admin) on host1.

jwx@ubunt-host1: ~/work $ git clonegit@X.X.X.X:gitosis-admin.git

jwx@ubunt-host1:  cd gitosis-admin.git

 

Under keydir directory, store ssh public key of users whowant to access git server.

So if root user in host1 what to access git server, he mustalso generates ssh key according to method used by jwx user (git admin in host1).

 Login root in host1

root@ubunt-host1:~# ssh-keygen –t rsa

 

copy theid_rsa.pub to keydir, and rename it asroot@ubuntu-host1.pub

root@ubunt-host1:~# mv .ssh/id_rsa.pub ~/work/gitisos-admin/keydir

 

 We can see that the jwx… file is admin jwx public key, and root… file us root user public key. Userswhose public key locate in keydir directory, have right to access git server.

 

Modify gitosis.conf to set users’ privilege.

Vi gitosis.conf

 

[gitosis]

[group gitosis-admin]

members = jwx@ubuntu-host1

writable = gitosis-admin

[group bmc]

writable = teamwork

members = jwx@ubuntu-host1 root@ubuntu-host1

 In this config file, the admin of git is jwx on host1, and jwx has right to r/w gitosis-admin; thebmc project has two members including jwx and root in host1. You also can setsome users only have readonly access to this project code as showing in the following:

readonly =  teamwork
members = otherusers

 

After the admin jwx has configured this file, then push itto remote git server to make it effect.

jwx@ubunt-host1:~/work/gitisos-admin Git add .

jwx@ubunt-host1:~/work/gitisos-admin Git commit –am “add configure and uses”

jwx@ubunt-host1:~/work/gitisos-adminGit  Git push origin master

 

(8)    Now ,we can use ourteamwork.git to code together

Init the null teamwork.git to be not empty in order to makeit can be cloned.

This operation can be done by any user whohas right to access teamwork.git (above gitosis.conf)

      Here, let root in host1 to do this work.

root@host1: ~/work$ mkdir teamwork-init

root@host1: ~/work/teamwork-init $ git init

root@host1: ~/work/teamwork-init $ vi README

root@host1: ~/work/teamwork-init $ git add .

root@host1: ~/work/teamwork-init $ git commit –am “initialversion”

root@host1: ~/work/teamwork-init $ git remote addorigingit@X.X.X.X:teamwork.git

root@host1: ~/work/teamwork-init $ git push originmaster

 

Then other users belonging to this project can clone teamwork.git for cooperation.

Here jwx on host1can do this:

jwx@host1: ~/home/jwx $ git clonegit@X.X.X.X:teamwork.git

….add or modify files…..

Git add …..

Git commit …

Git push origin master

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值