當前位置:首頁 » 操作系統 » linuxgit服務

linuxgit服務

發布時間: 2023-03-16 15:11:41

1. 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.

2. 如何在 Linux 上安裝 git 服務

1、yum方式安裝
# yum -y install git
如果提示系統提示沒有找到git包,可以採用下面的方式

2、下載Git源碼
官網:http://git-scm.com/
$ tar -xjvf git-1.7.4.1.tar.bz2
$ cd git-1.7.4.1/
$ make prefix=/usr/local all
$ make prefix=/usr/local install

3. 如何在 Linux 上安裝 git 服務

1、yum方式安裝
# yum -y install git
如果提示系統提示沒有找到git包,可以採用下面的方式岩碧悉

2、下載Git源碼包粗乎

$ tar -xjvf git-1.7.4.1.tar.bz2
$ cd git-1.7.4.1/
$ make prefix=/usr/local all
$ make prefix=/usr/慧顫local install

4. 如何在 Linux 上安裝 git 服務

安裝Optware IPKG。這個在QNAP官方的App Center里有提供,直接去安裝即可。
安裝Git。這里通過ipkg安裝的Git比較新。官方App Center里提供的git版本比較老。通過SSH登陸admin賬號後運行如下命令。
ipkg update
ipkg install git
初始化git伺服器端倉庫。你的git倉庫務必存放在非系統自帶的目錄下,否則系統重啟之後數據會被抹掉(我嘗試了是這樣的)。假定伺服器端git倉庫目錄為:/opt/repos,項目目錄為hets.git。通過SSH登陸admin賬號後運行如下命令。

5. 如何搭建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

http://www.linuxprobe.com/chapter-21.html#214_Git這篇是詳細介紹Git的,中間有一部分是怎麼去搭建,你可以看下

6. linux怎麼搭建git伺服器

GitHub就是一個免費託管開源代碼的遠程倉庫。但是對於某些視源代碼如生命的商業公司來說,既不想公開源代碼,又捨不得給GitHub交保護費,那就只能自己搭建一台Git伺服器作為私有倉庫使用。
搭建Git伺服器需要准備一台運行Linux的機器,強烈推薦用Ubuntu或Debian,這樣,通過幾條簡單的apt命令就可以完成安裝。
假設你已經有sudo許可權的用戶賬號,下面,正式開始安裝。
第一步,安裝git:
$ sudo apt-get install git

第二步,創建一個git用戶,用來運行git服務:
$ sudo adser git

第三步,創建證書登錄:
收集所有需要登錄的用戶的公鑰,就是他們自己的id_rsa.pub文件,把所有公鑰導入到/home/git/.ssh/authorized_keys文件里,一行一個。
第四步,初始化Git倉庫:
先選定一個目錄作為Git倉庫,假定是/srv/sample.git,在/srv目錄下輸入命令:
$ sudo git init --bare sample.git

Git就會創建一個裸倉庫,裸倉庫沒有工作區,因為伺服器上的Git倉庫純粹是為了共享,所以不讓用戶直接登錄到伺服器上去改工作區,並且伺服器上的Git倉庫通常都以.git結尾。然後,把owner改為git:
$ sudo chown -R git:git sample.git

第五步,禁用shell登錄:
出於安全考慮,第二步創建的git用戶不允許登錄shell,這可以通過編輯/etc/passwd文件完成。找到類似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash

改為:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

這樣,git用戶可以正常通過ssh使用git,但無法登錄shell,因為我們為git用戶指定的git-shell每次一登錄就自動退出。
第六步,克隆遠程倉庫:
現在,可以通過git clone命令克隆遠程倉庫了,在各自的電腦上運行:
$ git clone git@server:/srv/sample.git
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.

剩下的推送就簡單了。

7. 如何搭建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的,中間有一部分是怎麼去搭建,你可以看下

8. 如何在 Linux 上安裝 git 服務

Git 最初是一個在Linux下開發的非常流行的開源的版本控制系前運首統(VCS)。與其他的VCS工具(如CVS或者SVN)不同,Git在某種意義上考慮的是「分布式」,你本地的Git工作目錄就可以作為一個完整的版本控制庫並具有版本跟蹤能力。在這種模式中,每一個協作者都可以提交到本地倉庫,並且如果需要的話可以有選擇的推送到一個集中的版本倉庫。這種可擴展性和冗餘的修訂控制系統慧數是任何類型的大型協作任務中都是必須的。
一、通過包管理器安裝 Git
Git 是所有主要的Linux發行版本都附帶的功能。因此,安裝Git的最簡單的方法是使用您的Linux發行版的包管理器。
Debian, Ubuntu, or Linux Mint
$ sudo apt-get install git

Fedora, CentOS or RHEL
$ sudo yum install git

Arch Linux
$ sudo pacman -S git

OpenSUSE
$ sudo zypper install git

Gentoo
$ emerge --ask --verbose dev-vcs/git

二、從源代碼安裝Git
如果出於某種原因你想從源代碼安裝Git,你可以遵循下面的說明。
安裝依賴
構建之前,首先安裝Git依賴。
Debian,Ubuntu or Linux
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x

Fedora, CentOS or RHEL
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x

從源代碼編譯Git
從 https://github.com/git/git/releases 下載最新版本的 Git,然後在 /usr 目錄下構建悄褲和安裝 Git。
注意,如果你想安裝在一個其他的目錄(如 /opt ),可以替換配置命令行中的 「--prefix=/usr 」。
$ cd git-x.x.x
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info

9. 在Linux下搭建Git伺服器

眾所周知,版本系統在開發環境中是必不可少的,但是我們可以把代碼免費的託管到GitHub上,如果我們不原意公開項目的源代碼,公司又不想付費使用,那麼我們可以自己搭建一台Git伺服器,可以用Gitosis來管理公鑰,還是比較方便的。

搭建環境:

伺服器 CentOS6.6 + git(version 1.8.3.1)

客戶端 Windows10 + git(version 2.11.1.windows.1)

1. 安裝Git相關軟體

Linux是伺服器端系統,Windows作為客戶端系統,分別安裝Git

安裝客戶端:

下載 Git for Windows,地址:https://git-for-windows.github.io/

安裝完之後,可以使用Git Bash作為命令行客戶端。

安裝Gitosis

出現下面的信息表示安裝成功了

2. 伺服器端創建git用戶來管理Git服務

3. 配置公鑰

在Windows上配置管理者,git伺服器需要一些管理者,通過上傳開發者機器的公鑰到伺服器,添加成為git伺服器的管理者,打開git命令行

4. 配置gitosis

使用git用戶並初始化gitosis

在Windows上機器上clone gitosis-admin到管理者主機

gitosis.conf: git伺服器配置文件

keydir: 存放客戶端公鑰

配置 gitosis.conf 文件

在Windows管理者機器上創建本地test倉庫,並上傳到git服務端

提交到遠程伺服器

服務端會自動創建test倉庫

5.添加其他git用戶開發者

由於公司開發團隊人數不斷增多,手動添加開發者私鑰到/home/git/.ssh/authorized_keys比較麻煩,通過上面的Windows機器的管理者統一收集其他開發者的私鑰id_rsa.pub文件,然後傳到伺服器上,配置好後,用戶即獲得項目許可權,可以從遠程倉庫拉取和推送項目,達到共同開發項目。

推送完成後,新加進來的開發者就可以進行項目的開發了,後續增加人員可以這樣添加進來,開發者直接把倉庫clone下來就可以了。

10. linux如何搭建git

1、環境准備
伺服器:CentOS 7.3 + git (1.8.3.1)
客戶端:win10 + git (2.17.0.windows.1)
2、伺服器安裝git
yum install -y git
3、創建git用戶,管理 git服務
[root@localhost home]# useradd git
[root@localhost home]# passwd git
4、伺服器創建git 倉庫
設置/home/git/repository-git 為git 伺服器倉庫,然後把 git 倉庫的 owner 修改為 git 用戶。
復制代碼
[root@localhost git]# mkdir repository-git
[root@localhost git]# git init --bare repository-git/
Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/
5、客戶端安裝git
下載 Git for Windows,地址:https://git-for-windows.github.io/
安裝完之後,可以使用 Git Bash 作為命令行客戶端。
5.1、選擇一個目錄 F:\project\sell 作為本地倉庫,右鍵進入Git Bash 命令行模式
初始化本地倉庫:git init
5.2、嘗試克隆一個伺服器的空倉庫到本地倉庫
git clone [email protected]:/home/git/repository-gt
第一次連接到目標 Git 伺服器時會得到一個提示:
The authenticity of host '192.168.116.129(192.168.116.129)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/.
Are you sure you want to continue connecting (yes/no)?
選擇 yes:
Warning: Permanently added '192.168.116.129' (RSA) to the list of known hosts.
此時 C:\Users\用戶名\.ssh 下會多出一個文件 known_hosts,以後在這台電腦上再次連接目標 Git 伺服器時不會再提示上面的語句。

熱點內容
androidsdk32下載 發布:2025-08-24 16:36:35 瀏覽:266
安卓手機忘了解鎖密碼怎麼辦 發布:2025-08-24 16:35:09 瀏覽:789
存儲過程在java代碼 發布:2025-08-24 16:32:11 瀏覽:498
寫編譯器需要哪些知識 發布:2025-08-24 16:09:06 瀏覽:330
資料庫的關系符號 發布:2025-08-24 16:02:29 瀏覽:626
sqlserver表值函數 發布:2025-08-24 15:56:27 瀏覽:554
linuxc內存泄露 發布:2025-08-24 15:54:30 瀏覽:112
python讀取文件每一行 發布:2025-08-24 15:32:27 瀏覽:83
abbplc編程軟體 發布:2025-08-24 15:31:43 瀏覽:209
蘋果關閉密碼如何設置新密碼 發布:2025-08-24 14:28:41 瀏覽:299