Ubuntu 18.04 git倉庫服務器搭建


 

安裝git

sudo apt-get install git

創建賬戶git

創建Linux賬戶git,用來運行git服務

sudo adduser git

創建證書登錄

收集所有需要登錄的用戶的公鑰,公鑰位於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

這里的路徑中的git是賬戶名的名稱,/home/賬戶名/.ssh/authorized_keys,必須要所屬賬戶下。

初始化git倉庫

首先我們選定一個目錄作為Git倉庫,假定是/home/gitrepo/runoob.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/runoob.git/

以上命令Git創建一個空倉庫,服務器上的Git倉庫通常都以.git結尾。然后,把倉庫所屬用戶改為git:

chown -R git:git runoob.git

克隆倉庫

$ git clone git@192.168.0.106:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

192.168.0.106 為 Git 所在服務器 ip ,你需要將其修改為你自己的 Git 服務 ip。

此時,會報錯

ssh: connect to host 192.168.0.106 port 22: Connection refused
fatal: 無法讀取遠程倉庫。
請確認您有正確的訪問權限並且倉庫存在。

這個問題詳見Ubuntu18.04 ssh server配置

此時再去clone

$ git clone git@192.168.0.106:/home/gitrepo/runoob.git
正克隆到 'runoob'...
git@192.168.0.106's password: 
remote: 對象計數中: 3, 完成.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收對象中: 100% (3/3), 完成.

如此,我們的git倉庫就搭建完畢了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM