1. 程式人生 > >git-搭建企業git服務器

git-搭建企業git服務器

city 密鑰對 id_rsa 服務 http private stk span 直接

1.安裝 yum install git

2.增加用戶 useradd git -d /home/git -g git

3.查看公鑰鑒權文件是否存在 cat /home/git/.ssh/authorized_keys

4.不存在的話,新建

cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys

5.生成一個密鑰對

ssh-keygen -t rsa -C "fallshum"

是否輸入密碼,默認,一路Enter往下走就行

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:
1d:f1:b6:c9:42:2b:ab:1d:43:5a:72:fc:31:aa:38:9d fallshum
The key‘s randomart image is:
+--[ RSA 2048]----+
|          .      |
|           o     |
|          o o    |
|       . o = o   |
|      . S * +    |
|       * = +     |
|     ...= .      |
|    ..E+ o       |
|    ..o .        |
+-----------------+

5.1 把生成的公鑰寫入/home/git/.ssh/authorized_keys

cat /root/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys

查看 cat /home/git/.ssh/authorized_keys

5.2

把私鑰放到客戶端的.ssh目錄下,先獲取剛才生成的私鑰

cat /root/.ssh/id_rsa

復制出來放到本地客戶端

6.初始化Git倉庫 修改所有者
cd /home/git/

git init --bare fallshum.git

chown -R git:git fallshum.git/

5 客戶端克隆倉庫

客戶端打開Git Bash,clone服務端倉庫

git clone [email protected]:/home/git/fallshum.git

只要看到Checking connectivity... done就說明OK了

------------------------------------------------------------------------

遇到的問題 1:

The authenticity of host ‘IP‘ can‘t be established:

解決

https://yq.aliyun.com/articles/288093

解決方法

  1. 根據上面的理論,我們用下面的命令登錄就不會出問題了。
ssh  -o StrictHostKeyChecking=no username@47.95.xxx.xxx
  1. 還有一種方法是徹底去掉提示,修改/etc/ssh/ssh_config文件(或$HOME/.ssh/config)中的配置,添加如下兩行配置:
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

修改好配置後,重新啟動sshd服務即可,命令為:/etc/init.d/sshd restart (或 systemctl restart sshd )
當然,這是內網中非常信任的服務器之間的ssh連接,所以不考慮安全問題,就直接去掉了主機密鑰(host key)的檢查。

2.

git-搭建企業git服務器