當前位置:首頁 » 雲伺服器 » git遠程伺服器搭建

git遠程伺服器搭建

發布時間: 2022-11-27 19:53:16

A. 使用Gitolite搭建Git伺服器

Git服務的管理工具,主要有如下幾種。

Gitolite 使用perl語言編寫,維護和更新比較積極,下面測試使用Gitolite搭建Git伺服器。

一般新建用戶 ~/.ssh/ 目錄是不存在的。

生成路徑會在ssh-kengen執行後給出,也可修改。windows下生成路徑默認位於 C:/user/用戶名/.ssh 下。

此時, gitolite 會初始化兩個倉庫,同時創建 authorized_keys 文件

管理庫中有兩個目錄, conf/ 和 keydir/ 。

倉庫的創建通過編輯 gitolite-admin/conf/gitolite.conf 即可,然後將配置後的文件上傳伺服器。

若本地已有倉庫repo2,將其添加到伺服器

gitolite可以通過用戶組的方式進行管理

如上提示,需要輸入密碼。
需要安裝 openssh ,並將 gitolite 用戶添加在 sshusers 組中,有的伺服器可能是 ssh 組。

計算機領域的Cookbook指的是實用經典案例的意思,是對一些普遍性問題的解決方案的總結和整理。

B. linux搭建git遠程倉庫

1. linux和windows端分別安裝git,其中linux中可以用yum安裝

[root@node0~]#yum install git

git的默認安裝路徑在/usr/libexec/git-core

[root@node0 git-core]#cd /usr/libexec/git-core

[root@node0 git-core]#git --version

git version 1.7.1

2.設置linux端git的用戶名和密碼

[root@node0 git-core]# groupadd git

[root@node0 git-core]# useradd wang -g git

[root@node0 git-core]# passwd wang

New password:

3.在伺服器端創建遠程倉庫

[root@node0 ~]# mkdir -p /mnt/gitrep/wjf

[root@node0 ~]# cd /mnt/gitrep/wjf/

[root@node0 wjf]# git init

Initialized empty Git repository in /mnt/gitrep/wjf/.git/

把倉庫所屬用戶改為wang(git的用戶名)

[root@node0 wjf]# chown -R wang:git .git/

註:chown將指定文件的擁有者改為指定的用戶或組 -R處理指定目錄以及其子目錄下的所有文件

4.在windows客戶端克隆倉庫 

$ git clone [email protected]:/mnt/gitrep/wjf/.git

Cloning into 'wjf'...

The authenticity of host '192.168.111.60 (192.168.111.60)' can't be established.

RSA key fingerprint is SHA256:MgWCWF************************1m2tI.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '192.168.111.60' (RSA) to the list of known hosts.

[email protected]'s password:

第一次連接遠程倉庫,出現黑體部分,這是因為Git使用SSH連接,而SSH連接在第一次驗證GitHub伺服器的Key時,需要你確認GitHub的Key的指紋信息是否真的來自GitHub的伺服器,鍵入yes,然後輸入遠程倉庫的密碼就可以了。

5.實際中也通常通過設置公鑰的方式來連接遠程倉庫,這樣就不用每次連接都需要密碼了。

設置公鑰:

1.在windows客戶端的gitbash中生成用戶私鑰和公鑰

$ ssh-keygen -t rsa -C "[email protected]"

在c盤用戶路徑下的/.ssh文件夾下會生成私鑰id_rsa和公鑰id_rsa.pub

2.linux端

首先 Git伺服器打開RSA認證,即,修改/etc/ssh/sshd_config,將其中的以下三項打開

RSAAuthentication yes 

 PubkeyAuthentication yes 

 AuthorizedKeysFile .ssh/authorized_keys

然後,將客戶端生成的公鑰給到伺服器端

即,將公鑰給到 home/wang(git的用戶名)/.ssh/authorized_keys

[root@node0 ~]# cd /home/wang

[root@node0 wang]# mkdir .ssh

[root@node0 wang]# chmod 777 .ssh

[root@node0 wang]# touch .ssh/authorized_keys

在windows客戶端的gitbash中 執行:

$ ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

然後在linux端:

[root@node0 wang]# chmod 600 .ssh/authorized_keys

[root@node0 wang]# chmod 700 .ssh

[root@node0 wang]# chown wang:git .ssh

[root@node0 wang]# chown wang:git .ssh/authorized_keys 

至此,以後再連接遠程倉庫就不需要密碼了。

若仍需要密碼,可以查看ssh連接日誌/var/log/secure:

常見連接失敗原因:Authentication refused: bad ownership or modes for directory /home/wang/.ssh 

這時需要檢查該目錄的所屬用戶和讀寫許可權等級是否符合要求。公鑰以及.ssh文件的許可權應該屬於git的用戶和用戶組,讀寫許可權等級.ssh 700,authorized_keys 600.

C. 如何在mac下遠程搭建git伺服器

第一步,下載gitblit


http://gitblit.com/

這里當然是選擇linux/osx的版本。下載下來是一個.tar.gz的壓縮文件,我下載時最新版本是gitblit-1.7.1.tar.gz


D. 如何在mac下遠程搭建git伺服器

Git支持的協議主要是四種:
本地: 需要文件共享系統,許可權不好控制
HTTP:速度慢
SSH:同時支持讀寫操作,不支持匿名的讀取(Git默認協議)
GIT:最快

搭建的難易程度和特點綜合篩選,最合適的還是ssh,並且大部分伺服器上基本都有ssh服務,所以省去了不少麻煩。一個最基本的思路是給每一個人一個
ssh帳號,這樣大家就可以通過用戶名和口令來訪問了,但是顯然這不是一個好的選擇,這個做法有些多餘,並且對於repo的許可權很難管理。
在使用Github的時候,會利用rsa.pub公鑰/私鑰的方式,這樣在服務端擁有用戶的公鑰(*.pub)之後就可以,跨過繁瑣的口令,直接認證提交了,而服務端也會根據不同的用戶身份,對其許可權有著更加靈活的管理。因此我們也採用這種方式。
服務端
為了使遠程庫訪問更加直觀,先在伺服器上創建一個名為git的賬戶,這樣以後clone的時候就如下面的格式了:
git clone git@server:some.git
創建新的用戶,創建repo等目錄
$sudo adser git
$su git
$cd ——
$mkdir repos
在HOME下的。ssh目錄,如果沒有則創建,創建一個authorized_keys文件,這個文件就是用來管理所有git用戶的公鑰的,也就是這裡面的用戶對於項目有著R+W的許可權。
客戶端

於每一個客戶端,我們需要生成一對密鑰和公鑰,如果是Github用戶,那麼。ssh目錄下,一定有id_rsa.pub和id_rsa兩個文件,其中第
一個是系統生成的公鑰,另一個是自己要保存好的密鑰。如果沒有的話,可以在終端執行:ssh-keygen來生成,完成後,將自己的公鑰提交給管理員,這
就是一個注冊的行為。
完成
最後一步,管理員將團隊成員的公鑰添加到authorized_keys中,比如將同學susie加入:
$ cat susie.pub 》 authorized_keys
至此,大家可以通過git@server:repos/some.git來訪問公共的版本庫了。
問題
安全問題,成員可以登錄git用戶的shell,細節許可權如分支等不好控制
管理麻煩,新建repo,或者增加成員比較麻煩,尤其是修改的時候

E. 自己搭建git伺服器

剛開始是看的廖大神的git伺服器搭建,感覺看起來很難,因為是第一次在伺服器上搭建東西,因此看起來感覺一頓蒙,後來結合簡述上的一篇文展和廖大神的文章一並將git服務搭建起來,雖然別人看起來很簡單。。。

# 添加用戶

# 設定密碼

創建放置密鑰的文件,進入文件git bash,輸入下列命令

按照提示操作,成功後會出現兩個密鑰,私鑰和公鑰。

將生成的私鑰和公鑰放在工作目錄下,在伺服器端,找到上面創建的git用戶,即:

然後創建文件夾.ssh,在.ssh文件下創建文件authorized_keys,用來放置所有所有公鑰

進入粘貼公鑰

上面的server需要改為你自己的伺服器的IP地址

clone成功之後你會在你的工作目錄看到伺服器上面的sample文件

完成。。。。。。。。。。。。。。。。。。。

F. 如何搭建linux git伺服器

首先我們分別在Git伺服器和客戶機中安裝Git服務程序(剛剛實驗安裝過就不用安裝了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do

然後創建Git版本倉庫,一般規范的方式要以.git為後綴:
[root@linuxprobe ~]# mkdir linuxprobe.git

修改Git版本倉庫的所有者與所有組:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/

初始化Git版本倉庫:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/

其實此時你的Git伺服器就已經部署好了,但用戶還不能向你推送數據,也不能克隆你的Git版本倉庫,因為我們要在伺服器上開放至少一種支持Git的協議,比如HTTP/HTTPS/SSH等,現在用的最多的就是HTTPS和SSH,我們切換至Git客戶機來生成SSH密鑰:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+

將客戶機的公鑰傳遞給Git伺服器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.

此時就已經可以從Git伺服器中克隆版本倉庫了(此時目錄內沒有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#

初始化下Git工作環境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim

向Git版本倉庫中提交一個新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean

但是這次的操作還是只將文件提交到了本地的Git版本倉庫,並沒有推送到遠程Git伺服器,所以我們來定義下遠程的Git伺服器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git

將文件提交到遠程Git伺服器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.

為了驗證真的是推送到了遠程的Git服務,你可以換個目錄再克隆一份版本倉庫(雖然在工作中毫無意義):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository

這篇是詳細介紹Git的,中間有一部分是怎麼去搭建,你可以看下

G. 搭建Git伺服器及備份伺服器

OS:CentOS 7.2
Git:1.8.3.1

備份模式:

以下步驟以雙機備份為例,單機備份同理,只是在鏡像git項目的時候把git url換成單機中的git項目目錄即可。

首先,查看系統軟體庫中是否有git和git的版本:

CentOS 7.2環境下的輸出如下:

CentOS 7.x版本的倉庫中已經附帶了1.8.3.1版本的git,可以直接安裝。
CentOS 6.x中的git是1.7.x版本,自帶庫中git版本低的linux發行版可以添加git1.8.3.1的源來安裝git,但這個操作要求本機能訪問互聯網
其他版本的git理論上也可以,請自行測試

結果最後顯示「安裝完成」或「Complete」表示安裝成功。可以直接使用git命令測試一下:

輸出如下表示git安裝成功並可用。

創建一個git用戶,用來提供給外部用戶以git url的方式訪問git庫。

在用戶目錄或其他對外目錄中創建 /git/repos 目錄,用來存放git庫。

注意: 盡量使用git用戶來創建該目錄,方便以後git操作該目錄,如果是使用其他用戶創建的,記得使用以下命令將該目錄的owner改為git:

為了方便訪問,可以在根目錄下創建一個軟鏈連接到該目錄:

這樣設置後,假如以後有一個庫叫 test.git ,那麼就可以通過以下url來訪問git庫了:

創建一個測試庫用來測試備份及連通性。

同主GIT伺服器的《安裝git》章節。

同主GIT伺服器的《創建git庫目錄》章節。
目錄結構盡量與主git伺服器上的結構一致,如果不一致,使用軟鏈的形式將git url配置為與主git伺服器一致,這樣保證在切換伺服器時,客戶端不用做修改操作。

以上個步驟中創建的 test.git 為例:

這樣,主git伺服器中的 test.git 就鏡像到備份機中了。

如果主伺服器的git項目發生了變更,可以將變更同步到備份機。

將以上同步命令寫成腳本,添加一個定時任務來定時同步即可。
(待補充)

備份同步時每次都需要輸入主git伺服器的密碼,比較麻煩,也不利於定時同步的腳本操作,可以使用ssh免密登錄的方式,在主伺服器上配置備份伺服器的公鑰。

一路Enter(回車鍵),完成後會列印出密鑰的生成位置,通常在用戶主目錄的 .ssh 目錄中。默認情況下會生成以下兩個文件:

一定要注意上述命令中的第三步,許可權要設置對,否則認證不過去不能免密登錄。

如果在實際運行中,主git伺服器掛了一段時間,在這段時間里一直是備份git伺服器在工作,那麼在修復好主伺服器後需要將這一段時間的變更同步回主伺服器。

操作完成後備份庫自上一次同步後的更改都推送到了主庫。

H. 如何在mac下遠程搭建git伺服器

為有讀寫許可權的用戶建立一個分組。根據你的操作系統,你可以用groupadd命令來實現,用vigr來編輯分組文件,或者直接編輯/etc/group文件。在最後,你會在/etc/group文件中看到如下一行
?
1
repogroup:*:10005:marry,john,violet
其中,repogroup是准許接入這個倉庫的組的名字。10005是一個獨一無二的分組識別數字,marry,john,violet則是獲准接入這個倉庫的用戶。

決定Git倉庫的路徑。它既可以放在你的home路徑下(e.g. /home/yourname/gitroot),也可以放在一個專用的路徑下(e.g. /var/gitroot).
配置許可權,讓Git用戶可以訪問這個目錄
?
1
2
chmod g+rx /path-to/gitroot
chown :grouprepo /path-to/gitroot
建立新的Git倉庫,叫做newrepo
?
1
2
cd /path-to/gitroot
git init --bare newrepo.git
建立路徑認證,以允許用戶組訪問,同時有針對性的設置Git
?
1
2
3
4
5
cd newrepo.git
chown -R :grouprepo .
git config core.sharedRepository group
find . -type d -print0 | xargs -0 chmod 2770
find . -type f -print0 | xargs -0 chmod g=u
設置提交(commit)的email通知(commit是一條命令),這樣當有新的修改提交到倉庫的時候,開發者們將會收到一封關於修改內容一覽的電子郵件。
?
1
2
3
4
5
6
7
echo 'One-line project description' >description
git config --local hooks.mailinglist [email protected]<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script>,[email protected]<script cf-hash="f9e31" type="text/javascript">
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */</script>,...
git config --local hooks.emailprefix '[DI-PR] '
git config --local hooks.showrev "git show -C %s; echo"
git config --local hooks.emailmaxlines 100
通過設置一個稱為鉤子(hook)的東東,來創建這些email通知。

熱點內容
文件夾審計 發布:2024-03-28 17:08:20 瀏覽:241
密碼反編譯是什麼意思 發布:2024-03-28 17:02:54 瀏覽:309
linux下samba 發布:2024-03-28 16:54:12 瀏覽:539
我的世界國際服手機版免費開伺服器 發布:2024-03-28 16:45:36 瀏覽:284
phpmongodb擴展下載 發布:2024-03-28 16:41:03 瀏覽:323
android開發教程筆記 發布:2024-03-28 16:31:48 瀏覽:771
榮威i6max配置怎麼選 發布:2024-03-28 16:18:11 瀏覽:455
cml編程 發布:2024-03-28 16:14:53 瀏覽:758
linuxc語言文件讀寫 發布:2024-03-28 15:59:57 瀏覽:579
點遍歷演算法 發布:2024-03-28 15:57:34 瀏覽:497