Liunx 伺服器新增 SSH 存取Git / CentOs

2020-09-27 08:01:20

Liunx 伺服器新增 SSH 存取Git / CentOs


1、看看目錄是否存在

ls -al ~/.ssh

2、生成金鑰

ssh-keygen -t rsa -C "347969164@qq.com"

操作

Enter file in which to save the key (/home/qy/.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:
SHA256:joUMKG8+3KkO8dbpRyvHYgOG8ufydZNL3jkMYYB6mO8 347969164@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|     .           |
|   .. .          |
|. .+.  .         |
| o+ .o .o        |
|..oo  o.S.       |
|o*oo.o.+..       |
|oo*o=oo.*o       |
| oo+E.=+ +o.     |
| .o*+*  o o.     |
+----[SHA256]-----+

3、得到 agent pid

eval $(ssh-agent -s)

輸出

Agent pid 22939

4、將 ssh 私鑰新增到 ssh 代理中。如果使用不同的名稱建立了金鑰, 或者新增了具有不同名稱的現有金鑰, 請用私鑰檔案的名稱替換該命令中的 id_rsa

ssh-add ~/.ssh/id_rsa

5、複製 SSH key 到剪下板

6、到Git 新增公鑰

7、伺服器確認

gitee 的

ssh -T git@gitee.com

github的

ssh -T git@github.com

操作流程

# The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
# ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
# ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
# Are you sure you want to continue connecting (yes/no)? yes
# 輸入 yes
# Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
# Enter passphrase for key '/root/.ssh/id_rsa':
# 輸入公鑰密碼
# Hi 簡簡單單OnlineZuozuo! You've successfully authenticated, but GITEE.COM does not provide shell access.
# 成功

簡簡單單OnlineZuozuo CSDN認證部落格專家 Spring 架構 分散式
未聞萬里蓬萊,而窺先聖遺智。故,以此生築夢,奔而逐之;以泰山之偉,攀而登之;以靜雅素心,處世為人。------zuozuo著