文章

Git Server - Ubuntu

Git Server 在Ubuntu上部署和使用。

Git Server Install

install openssh server and client

1
sudo apt-get install openssh-server openssh-client

install git server

1
sudo apt-get install git-core

config git server

new a git user to git server

1
2
sudo useradd -m git
sudo passwd git

init global name

1
2
git config --global user.name "kllmctrl"
git config --global user.email "kllmctrl@gmail.com"

install python

1
sudo apt-get install python-setuptools

install gitosis

1
2
3
4
cd /tmp
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis
sudo python setup.py install

Git Server Authorization

mac authorization

1
ssh-keygen -t rsa

config keygen on git server

on mac console

1
sudo scp .ssh/id_rsa.pub git@192.168.176.136:/tmp

on git server console

1
2
sudo chmod a+r /tmp/id_rsa.pub
sudo -H -u git gitosis-init < /tmp/id_rsa.pub

so /home/git will appear gitosis and repositores(contain gitosis-admin.git)

set root user:sudo passwd root sign in root:su root

set some files to read

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

test a git

1
2
3
4
5
su git
cd /home/git/repositories
mkdir test.git
cd test.git
git init --bare

on mac console

1
2
3
cd /home/work/config-git-server
git clone git@192.168.176.136:gitosis-admin.git
cd gitosis-admin.git

put Authorization users.pub to keydir floders ,example A.pub B.pub

then modify gitosis.conf

1
2
3
4
5
6
7
8
9
[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = weedcatch@weedcathtekiMac.local.pub

[group test]
writable = test
members = weedcatch@weedcathtekiMac.local.pub A B

comit config to git server

1
2
3
4
cd gitosis-admin
git add .
git commit -am "add test project and users"
git push origin master

GitWeb brower the git server

install apache2

1
sudo apt-get install apache2

install gitweb

1
sudo apt-get install gitweb

if no the gitweb floders then you can clone the git.git and copy the git/gitweb to path

config gitweb

1
2
3
sudo cp /etc/apache2/conf.d/gitweb /etc/apache2/conf-available/gitweb.conf
cd /etc/apache2/conf-enabled
sudo ln -s ../conf-available/gitweb.conf

modify:gitweb.conf

1
2
3
4
5
6
7
8
9
#<VirtualHost *:8056>
	Alias /gitweb /usr/share/gitweb
	<Directory /usr/share/gitweb>
		Options +FollowSymLinks +ExecCGI
		AddHandler cgi-script .cgi
	</Directory>
	ServerName localhost
#</VirtualHost>

cd /var/www/ sudo ln -s /usr/share/gitweb/* .

then modify: sudo vi /etc/gitweb.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
	# path to git projects (<project>.git)
	#$projectroot = "/var/cache/git";
	$projectroot = "/home/git/repositories";
	# directory to use for temp files
	$git_temp = "/tmp";
	# target of the home link on top of all pages
	$home_link = $my_uri || "/";
	# html text to include at home page
	$home_text = "indextext.html";
	# file with project list; by default, simply scan the projectroot dir.
	$projects_list = $projectroot;
	# stylesheet to use
	@stylesheets = ("/gitweb/static/gitweb.css");
	# javascript code for gitweb
	$javascript = "/gitweb/static/gitweb.js";
	# logo to use
	$logo = "/gitweb/static/git-logo.png";
	# the 'favicon'
	$favicon = "/gitweb/static/git-favicon.png";
	# git-diff-tree(1) options to use for generated patches
	#@diff_opts = ("-M");
@diff_opts = ();

modify:/etc/apache2/conf.d/gitweb

and modify:

/var/www/gitweb.cgi css.path…. add /gitweb/static/…. etc.

restart apacha2

1
2
sudo a2enmod cgi
sudo service apache2 restart

brower site

1
http://localhost/cgi-bin/gitweb.cgi

Use git for users

common

1
2
git clone git@192.168.176.136:test.git

Tower on mac

ssh://192.168.176.136/test.git user:git pwd:…..

本文由作者按照 CC BY 4.0 进行授权