创建公私钥对连接远程仓库

Posted mozq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建公私钥对连接远程仓库相关的知识,希望对你有一定的参考价值。

创建公私钥对连接远程仓库

参考

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:Users1.ssh>tree /f
卷 Windows 的文件夹 PATH 列表
卷序列号为 AE9A-3125
C:.
│  id_rsa
│  id_rsa.pub
│  known_hosts

同时连接多个库,这些库默认都是读取id_rsa文件,可以建立文件夹,用哪个库把哪个库的rsa文件粘贴出来。比如我要用学成的公私钥,我就把他粘贴出来放到 .ssh文件夹中。

C:Users1.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:Users1.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.

以上是关于创建公私钥对连接远程仓库的主要内容,如果未能解决你的问题,请参考以下文章

git 本地仓库与远程仓库关联

公私钥生成

使用 SSH 秘钥远程连接

如何使用openssl生成RSA公钥和私钥对 / 蓝讯

git本地仓库与远程仓库建立连接

git之remote repository create(远程仓库创建)