Git 服務器搭建
Github 公開的項目是免費的,但是如果你不想讓其他人看到你的項目就需要收費。
這時我們就需要自己搭建一臺Git服務器作爲私有倉庫使用。
接下來我們將以 Centos 爲例搭建 Git 服務器。
1、安裝Git
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel $ yum install git
接下來我們 創建一個git用戶組和用戶,用來運行git服務:
$ groupadd git $ useradd git -g git
2、創建證書登錄
收集所有需要登錄的用戶的公鑰,公鑰位於id_rsa.pub文件中,把我們的公鑰導入到/home/git/.ssh/authorized_keys文件裏,一行一個。
如果沒有該文件創建它:
$ cd /home/git/ $ mkdir .ssh $ chmod 755 .ssh $ touch .ssh/authorized_keys $ chmod 644 .ssh/authorized_keys
3、初始化Git倉庫
首先我們選定一個目錄作爲Git倉庫,假定是/home/gitrepo/test.git,在/home/gitrepo目錄下輸入命令:
$ cd /home $ mkdir gitrepo $ chown git:git gitrepo/ $ cd gitrepo $ git init --bare runoob.git Initialized empty Git repository in /home/gitrepo/test.git/
以上命令Git創建一個空倉庫,服務器上的Git倉庫通常都以.git結尾。然後,把倉庫所屬用戶改爲git:
$ chown -R git:git test.git
4、克隆倉庫
$ git clone [email protected]:/home/gitrepo/test.git Cloning into 'test'... warning: You appear to have cloned an empty repository. Checking connectivity... done.
192.168.45.4 爲 Git 所在服務器 ip ,你需要將其修改爲你自己的 Git 服務 ip。
這樣我們的 Git 服務器安裝就完成。