創建公私鑰對連接遠程倉庫


創建公私鑰對連接遠程倉庫

參考

https://gitee.com/help/articles/4181#article-header0

步驟

ssh-keygen -t rsa -C "1215135027@qq.com" 在本地生成 rsa 公私鑰。直接回車。名稱必須是默認的id_rsa

將公鑰保存到碼雲

ssh -T git@gitee.com 測試連接生成 known_hosts 文件,測試連接的時候要輸入 yes 不能直接回車

ssh-keygen生成公私鑰

1@DESKTOP-3H9092J MINGW64 /e/mozq/00store/01
$ ssh-keygen -t rsa -C "1215135027@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/1/.ssh/id_rsa.
Your public key has been saved in /c/Users/1/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:3n4Ctfa9e59mAKmFxxY+4z+3i7Y73vrB46iAO9wL5q0 1215135027@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|           .     |
|          + o    |
|         ..@     |
|        S.*.+    |
|       .ooo. ..  |
|      .+o+.....+ |
|      oo+oo o=*+=|
|       Eooo++B&@=|
+----[SHA256]-----+

碼雲配置公鑰

設置 > 安全設置 > SSH公鑰

測試連接生成know_hosts文件

1@DESKTOP-3H9092J MINGW64 /e/mozq/00store/01
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.62.174)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com,212.64.62.174' (ECDSA) to the list of known hosts.
Hi 魔有追求! You've successfully authenticated, but GITEE.COM does not provide shell access.

注意

私鑰名稱必須為默認的id_rsa,並且放在用戶目錄的.ssh文件夾下。

C:\Users\1\.ssh>tree /f
卷 Windows 的文件夾 PATH 列表
卷序列號為 AE9A-3125
C:.
│  id_rsa
│  id_rsa.pub
│  known_hosts

同時連接多個庫,這些庫默認都是讀取id_rsa文件,可以建立文件夾,用哪個庫把哪個庫的rsa文件粘貼出來。比如我要用學成的公私鑰,我就把他粘貼出來放到 .ssh文件夾中。

C:\Users\1\.ssh>tree /f
卷 Windows 的文件夾 PATH 列表
卷序列號為 AE9A-3125
C:.
│  id_rsa
│  id_rsa.pub
│  known_hosts
│
├─sand
│      id_rsa
│      id_rsa.pub
│      known_hosts
│
├─store_sand
│      id_rsa
│      id_rsa.pub
│      known_hosts
│
└─xc
        id_rsa
        id_rsa.pub
        known_hosts

bugs

# 生成的私鑰名稱必須為id_rsa,也就是默認的名稱,不然的話也會找不到。
C:\Users\1\.ssh>tree /f
卷 Windows 的文件夾 PATH 列表
卷序列號為 AE9A-3125
C:.
│  id_rsa
│  id_rsa.pub
│  known_hosts
# 連接測試時如果直接回車,不輸入yes,則會顯示被拒絕。輸入yes則會連接成功。
1@DESKTOP-3H9092J MINGW64 /e/mozq/00store/01
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.62.174)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Host key verification failed.

# 連接測試時如果直接回車,輸入yes連接成功。
1@DESKTOP-3H9092J MINGW64 /e/mozq/00store/01
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.62.174)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com,212.64.62.174' (ECDSA) to the list of known hosts.
Hi 魔有追求! You've successfully authenticated, but GITEE.COM does not provide shell access.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM