Git 遠端服務搭建 CentOS7

2021-10-02 12:47:13 字數 1746 閱讀 7019

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

[root@localhost ~]# yum install git

建立乙個 git 使用者組和使用者,用來執行 git 服務

[root@localhost ~]# groupadd git

[root@localhost ~]# adduser git -g git

收集所有需要登入的使用者的公鑰,公鑰位於 ~/.ssh/id_rsa.pub 檔案中

把每個開發者的公鑰匯入到 /home/git/.ssh/authorized_keys 檔案裡,一行乙個

如果沒有 /home/git/.ssh/authorized_keys 檔案則使用下面的命令建立

[root@localhost ~]# cd /home/git/

[root@localhost git]# mkdir .ssh

[root@localhost git]# chmod 700 .ssh

[root@localhost git]# touch .ssh/authorized_keys

[root@localhost git]# chmod 600 .ssh/authorized_keys

首先我們選定乙個目錄作為 git 倉庫的根目錄,一般情況下我們會在 git 使用者目錄下建立 repo 目錄作為 git 服務的根目錄

首先切換到 git 使用者

[root@localhost git]# su git

[git@localhost ~]$ mkdir /home/git/repo

[git@localhost ~]$ chown /home/git/repo git:git

然後在 repo 目錄下建立我們的 git 專案目錄,比如 git-demo.git

目錄名最好以 .git 結尾,這樣在 git clone 或者 push 的時候 url 路徑更直觀

[git@localhost ~]$ cd /home/home/git/repo

[git@localhost ~]$ mkdir git-demo.git

[git@localhost ~]$ chown git:git git-demo.git

[git@localhost ~]$ cd git-demo.git

[git@localhost ~]$ git init --bare .

initialized empty git repository in /home/git/repo/git-demo.git/

編輯 /etc/passwd 檔案完成,找到有 git 那行

git:x:503:503::/home/git:/bin/bash
改為:

git:x:503:503::/home/git:/sbin/nologin
現在我們就可以轉殖這個遠端倉庫了,假設我們伺服器的 ip 是 192.168.1.8

如果出現類似的 clone into 語句,則說明我們的 遠端 git 服務配置完成了

Centos搭建遠端GIT伺服器

1.centos下安裝git網上太多的教程了。不多說。2.建立目錄 data git 3.建立乙個使用者 useradd r s bin sh c git version control d data git git 4.在下面初始化乙個git repository庫 git init bare p...

centos搭建git服務

上一章節中我們遠端倉庫使用了 github,github 公開的專案是免費的,但是如果你不想讓其他人看到你的專案就需要收費。這時我們就需要自己搭建一台git伺服器作為私有倉庫使用。接下來我們將以 centos 為例搭建 git 伺服器。yum install curl devel expat dev...

Centos上搭建git服務

yum install curl devel expat devel gettext devel openssl devel zlib devel perl devel yum install git 接下來我們 建立乙個git使用者組和使用者,用來執行git服務 groupadd git addu...