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 “[email protected]

 

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.email[email protected]

 

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 [email protected]:/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 clone[email protected]: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 as[email protected]

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 addorigin[email protected]: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 clone[email protected]:teamwork.git

….add or modify files…..

Git add …..

Git commit …

Git push origin master

 

 

 

你可能感兴趣的:(Set up git server on ubuntu using ssh protocol(已经测试可以))