零起步5-CentOS7.6源碼編譯安裝git-2.24.1

安裝 git-2.24.1
 
 
準備工作1:下載安裝包及相關依賴,git有幾個依賴 openssl openssl-devel curl-devel expat-devel,已安裝的不用重複安裝
 
[root@localhost ~]# wget https://github.com/git/git/archive/v2.24.1.tar.gz
[root@localhost ~]# yum install expat-devel openssl openssl-devel curl-devel -y

 

 
 
編譯安裝 
 
[root@localhost ~]# tar zxvf v2.24.1.tar.gz
[root@localhost ~]# cd git-2.24.1/
[root@localhost git-2.24.1]# make prefix=/usr/local/git all
[root@localhost git-2.24.1]# make prefix=/usr/local/git install
[root@localhost git-2.24.1]# cd ..

 

 
配置環境變量,添加git用戶和組(禁用shell登錄)
 
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
[root@localhost ~]# source /etc/bashrc
[root@localhost ~]# groupadd git
[root@localhost ~]# useradd git -g git
[root@localhost ~]# su - git
[git@localhost ~]$ cat /etc/passwd |grep git
git:x:1002:1002::/home/git:/bin/bash

 

 
至此,git服務安裝完成!
 
安裝報錯及處理辦法
 
git-compat-util.h:283:25: 致命錯誤:openssl/ssl.h:沒有那個文件或目錄
yum install openssl openssl-devel  -y
 
http.h:6:23: 致命錯誤:curl/curl.h:沒有那個文件或目錄
yum -y install curl-devel -y
 
http-push.c:22:19: 致命錯誤:expat.h:沒有那個文件或目錄
yum install expat-devel -y
 
 
Git服務器配置
 
創建證書登錄
 
添加證書之前,還要做這麼一步: Git服務器打開RSA認證 。在Git服務器上首先需要將/etc/ssh/sshd_config中的RSA認證打開,即將sshd_config文件中下面幾個的註釋解開
1. RSAAuthentication yes 
2. PubkeyAuthentication yes 
3. AuthorizedKeysFile .ssh/authorized_keys
 
所以我們在/home/git下創建.ssh目錄,然後創建authorized_keys文件,再設置私鑰,創建公鑰
 
[root@localhost ~]# su - git
[git@localhost ~]$ cd /home/git/ 
[git@localhost ~]$ mkdir .ssh 
[git@localhost ~]$ chmod 700 .ssh 
[git@localhost ~]$ touch .ssh/authorized_keys 
[git@localhost ~]$ chmod 600 .ssh/authorized_keys
[git@localhost ~]$ cd ~/.ssh
[git@localhost .ssh]$ ll
總用量 0
-rw-------. 1 git git 0 12月 21 06:55 authorized_keys

[git@localhost .ssh]$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/git/.ssh/id_rsa): authorized_keys
authorized_keys already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in authorized_keys.
Your public key has been saved in authorized_keys.pub.
The key fingerprint is:
SHA256:sBSBC4rSnkFUgZBkNKN1eerEewgAhmXLL2UvxieEHK8 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|B%*o++o.         |
|B=**o ..         |
|o==o=+o          |
|+ +B=o o         |
|..E**o+ S        |
|  oo++.          |
|     .           |
|                 |
|                 |
+----[SHA256]-----+

[git@localhost .ssh]$ ll
總用量 8
-rw-------. 1 git git 1766 12月 21 06:59 authorized_keys
-rw-r--r--. 1 git git  403 12月 21 06:59 authorized_keys.pub
[git@localhost .ssh]$ cat authorized_keys.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkzB8FpT6oVnVhhwp3vd7EsXICgiLwMnlyM8/If9Rh8sfiWKOWbQK2tUsLi9H6SEdpolNyUwdM/+gfkMGYJz2Kjw7IUESJol5WGK+DSNkM2NLF8k/Z2VVSHKE06Crgq+94NTwgGpukZ2o0oTeZjEELMC62RvC9bS+ALv+y7Au87fiOcdeOG2+uR0T1OZIeDSF4zEsnSVAw+PumXptol8oGqiA2jqTDfoeF28tC4JkYviMdTGegSzpDOC4sK0N/+ZZAMznetlXst7iTtIFSbnnFA7pXdovPF8zfxa8hlQjejomYD7mx6i0tSDzRofMwveOdUFKTXgZqEBTc9ZA1KNnT [email protected]

 
上面的authorized_keys.pub即爲生成的公鑰,將公鑰內容拷貝到 github中,
登錄http://github.com,鼠標移到右上角的圖標進入個人設置頁面,title隨便填,key填入cat authorized_keys.pub 如上輸出的紅色內容
Settings -->  SSH and GPG keys  -->  New SSH key
 
最後一步,將私鑰加入到本地計算機的ssh-agent 中,因爲現在私鑰存儲在本地計算機中,但跟GitHub 建立連接的時候,實際上是本機計算機的 ssh-agent 與 GitHub 服務器進行通信,ssh-agent並不知道私鑰存儲在哪兒,所以要有以下操作
 
[git@localhost .ssh]$ ssh-add ~/.ssh/authorized_keys
Could not open a connection to your authentication agent.
[git@localhost .ssh]$ eval `ssh-agent  -s`
Agent pid 43025
[git@localhost .ssh]$ ssh-add ~/.ssh/authorized_keys
Enter passphrase for /home/git/.ssh/authorized_keys:
Identity added: /home/git/.ssh/authorized_keys (/home/git/.ssh/authorized_keys)
[git@localhost .ssh]$ ssh-add -l
2048 SHA256:sBSBC4rSnkFUgZBkNKN1eerEewgAhmXLL2UvxieEHK8 /home/git/.ssh/authorized_keys (RSA)

 

 
一切準備就緒,測試與github的通信
 
[git@localhost .ssh]$ ssh -T [email protected]
 
如果連接成功,應該會有以下提示,這表明git服務搭建成功
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
 
再切換到root用戶,修改git權限,只允許ssh連接來推送和獲取git倉庫,禁止shell登錄,將
git:x:1002:1002::/home/git:/bin/bash
改爲
git:x:1002:1002::/home/git:/usr/local/git/bin/git-shell
 
[git@localhost ~]$ su
密碼:
[root@localhost ~]# vi /etc/passwd
[root@localhost ~]# cat /etc/passwd |grep git
git:x:1002:1002::/home/git:/usr/local/git/bin/git-shell

 

 
 
 
錯誤一:沒有將pubKey添加到github導致的驗證失敗
debug1: No more authentication methods to try.
Permission denied (publickey).
 
錯誤二:保存在本地計算機的私鑰沒有加入到本地計算機的ssh-agent 中
Could not open a connection to your authentication agent.
 
警告:將RSA連接的github  IP和github.com域名持久綁定到hosts中(也可不理會)
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
 
[root@localhost ~]# vi /etc/hosts
 
加入以下內容在文件最後,保存退出
13.250.177.223 github.com
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章