Ubuntu下搭建gitosis

1、安裝openssh

sudo apt-get install openssh-server openssh-client

2、創(chuàng)建個人公鑰和私鑰(在默認用戶的主目錄路徑下,運行一下命令)

ssh -keygen -t rsa

默認生成2048位,如果需要提高安全級別,也可以通過下面的命令創(chuàng)建公鑰和私鑰

ssh -keygen -t rsa -b 4096

默認情況下,公鑰和私鑰會保存在~/,ssh目錄下,如下所示:

id_rsa ? ? ?id_rsa.pub ?known_hosts

3、安裝git服務器

sudo apt-get install git-core

4、配置git服務器

4.1創(chuàng)建git服務器管理用戶()

? ? sudo useradd -m git

? ? sudo passwd ?git

4.2、創(chuàng)建git倉庫存儲目錄

? ? sudo mkdir ?/home/git/repositories

4.3、設置git倉庫權限

? ? sudo chown git:git ?/home/git/repositories

? ? sudo chmod 755 ?/home/git/repositories

4.5、初始化全局設置

? ? ?git ?config ?--global user.name "myname"

? ? ?git ?config ?-global ?user.email ? "myname@163.com"

5、安裝python的setup ?tool

sudo apt-get install python-setuptools

6、獲取并安裝gitosis

cd ?/tmp

git ?clone ?https://github.com/res0nat0r/gitosis.git

cd ?gitosis?

sudo python setup.py install

7、配置gitosi

cp ~/.ssh/id_rsa.pub /tmp

sudo -H -u git gitosis-init < /tmp/id_rsa.pub

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

8、管理gitosis配置

cd ~

git clone git@hostname:用戶名/gitosis-admin.git

cd gitosis-admin/

各個用戶按照前面提到的辦法生成各自的ssh公鑰文件后,服務器管理員把所有人的 ssh公鑰文件都拿來,拷貝到keydir目錄下。

修改gitosis.conf文件,如下所示:

[gitosis]

[group gitosis-admin] ? ??writable = gitosis-admin ? ??members = a@server1

[group developers] ? ??writable = helloworld ? ?members = a@server1 b@server2

[group test] ??readonly = helloworld ? ??members = c@server3

這個配置文件表達了如下含義:gitosis-admin組成員有a,該組對gitosis-admin倉庫有讀寫權限; developers組有a,b兩個成員,該組對helloworld倉庫有讀寫權限; test組有c一個成員,對helloworld倉庫有只讀權限。 當然目前這些配置文件的修改只是在你的本地,你必須推送到gitserver上才能真正生效。 加入新文件、提交并push到git服務器:

git add .

git commit -am "add helloworld project and users"

git remote add origin ssh://git@hostname/helloworld.git

git push origin master

9、安裝apache2

sudo apt-get install apache2

10、安裝gitweb’

sudo apt-get install gitweb

11、配置gitweb

默認沒有 css 加載,把 gitweb 要用的靜態(tài)文件連接到 DocumentRoot 下:

cd /var/www/

sudo ln -s /usr/share/gitweb/* .

修改配置:

sudo vi ?/etc/gitweb.conf

將 $projectroot 改為git倉庫存儲目錄(例如:/home/git/repositories),保存后刷新瀏覽器。

如果沒有找到項目,你需要將$projectroot/*.git 的屬性改為755,讓apache用戶有可讀權限??梢灾桓哪阈枰寗e人通過web訪問的那個git。http://localhost/cgi-bin/gitweb.cgi

修改/etc/gitweb.conf內(nèi)容

# path to git projects (.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 = ();

12、配置apache2

ubuntu中默認的web目錄是/var/www,默認的cgi目錄是 /usr/lib/cgi-bin/,安裝完成gitweb后,gitweb的gitweb.cgi會自動放置到該目錄下。

如果你的cgi路徑不是默認的/usr/lib/cgi-bin/,需要將gitweb安裝在/usr/lib/cgi-bin中的gitweb.cgi復制到原來配置的cgi-bin路徑,并在apache的配置文件/etc/apache2/apache.conf末尾加上以下內(nèi)容:

SetEnv? GITWEB_CONFIG? /etc/gitweb.conf

Options FollowSymlinks ExecCGI

Allow from all

AllowOverride all

Order allow,deny

SetHandler cgi-script

RewriteEngine on

RewriteCond?%{REQUEST_FILENAME}?!-f

RewriteCond?%{REQUEST_FILENAME}?!-d

RewriteRule ^.* /gitweb.cgi/$0 [L,PT]

重新啟動apache:sudo /etc/init.d/apache2 restart,訪問http://localhost/cgi-bin/gitweb.cgi

出現(xiàn)如圖所示,說明成功了

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容