最近剛弄了個阿里雲,在上面弄個git服務器,這里只弄了ssh方式訪問,http方式訪問的可以看我另外一個隨筆http://www.cnblogs.com/hz-cww/p/6077970.html。
1、 安裝依賴的庫
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
2、 刪除原本的安裝的git
[root@localhost ~]# yum remove git -y
3、下載git-2.10.0.tar.gz 到 /usr/local/src
[root@localhost ~]# cd /usr/local/src [root@localhost src]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz
4、 編譯安裝
[root@localhost src]# tar -zvxf git-2.10.0.tar.gz [root@localhost src]# cd git-2.10.0 [root@localhost src]# make prefix=/usr/local/git all [root@localhost src]# make prefix=/usr/local/git install
5、 增加軟連接
[root@localhost src]# ln -s /usr/local/git/bin/* /usr/bin/ [root@localhost src]# git --version
如果能正常顯示版本號,即表示成功
6、新建git用戶和設置密碼
[root@localhost ~]# useradd -m git [root@localhost ~]# passwd git
7、新建git的倉庫,並設置權限,我這邊是建立repositories這個文件夾
[root@localhost ~]# mkdir -p /home/git/repositories [root@localhost ~]# chown -R git:git /home/git/repositories [root@localhost ~]# chmod 755 /home/git/repositories
8、切換到git用戶下,新建倉庫
[root@localhost ~]# su git [git@localhost root]$ mkdir /home/git/repositories/test.git [git@localhost root]$ cd /home/git/repositories/test.git [git@localhost test.git]$ git --bare init
ok,到這里簡單的git服務器已經建立好了,你可以去客戶端機子上clone了
地址:ssh://git@這里寫你的IP/home/git/repositories/test.git
9、禁用git用戶的shell登陸,修改/etc/passwd文件
[root@localhost ~]# vi /etc/passwd
找到這一行
git:x:1001:1001:,,,:/home/git:/bin/bash
將最后一個冒號后改為:
git:x:1001:1001:,,,:/home/git:/usr/src/git-2.10.0/git-shell
這樣,git用戶可以正常通過ssh使用git,但無法登錄shell,因為我們為git用戶指定的git-shell每次一登錄就自動退出。
10、附加:下一次新建git倉庫時,shell只能用root登錄
[root@localhost root]$ mkdir /home/git/repositories/test2.git [root@localhost root]$ cd /home/git/repositories/test2.git [root@localhost test.git]$ git --bare init
這里新建完之后,必須將新建的git倉庫更改所有者為git用戶,不然無法連接,執行下面命令,
注意這里-R必須加上,不然git用戶clone會出現權限不夠問題
[root@localhost ~]# chown -R git:git /home/git/repositories
ok,到這里就基本搞定。