目 录CONTENT

文章目录

SSH 生成RSA私钥、公钥

ABin
2022-06-08 / 0 评论 / 0 点赞 / 21 阅读 / 0 字

D:

  1. 生成rsa公钥和密钥
  2. 起名: id_rsa_demo
  3. 文件已经存在了,提示是否覆盖 (不存在则跳过此步骤
  4. 是否设置密码,不设置直接 回车 2次
  5. 创建完成
  6. 添加生成的 SSH key 到 ssh-agent

C:

1.命令上输入以下代码

ssh-keygen -t rsa 
#或
ssh-keygen -t rsa -C "Admin@abin"

2.起名: id_rsa_demo

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa): id_rsa_demo

3.文件已经存在了,提示是否覆盖 (不存在则跳过此步骤

id_rsa_demo already exists.
Overwrite (y/n)? 

4.是否设置密码,不设置直接 回车 2次

Enter passphrase (empty for no passphrase): 
Enter same passphrase again:

5.创建完成

Your identification has been saved in id_rsa_demo
Your public key has been saved in id_rsa_demo.pub
The key fingerprint is:
SHA256:R/vNObOcegGWwacbDSNEpPOcg9jyGz8UrB+SkeWYvm4 ABin@192.168.1.10 #不添加 -C 'demo' 会自动填写
The key's randomart image is:
+---[RSA 3072]----+
|         ++.     |
|         .o = .  |
|        oB.. O   |
|       o=*+o* .  |
|      o.S+Bo +   |
|       o=.oo.o.. |
|        o= .. *. |
|        E+o  ..= |
|       oo ...o+  |
+----[SHA256]-----+

完成

~/.ssh 目录下会生成 id_rsa 和 id_rsa.pub 两个文件

6.添加生成的 SSH key 到 ssh-agent

ssh-add ~/.ssh/id_rsa
Identity added: ./id_rsa (Admin@ABin.Pro)

公钥(id_rsa_demo.pub) 可以放到其他服务器,私钥(id_rsa_demo)请保存好

测试

ssh -T gitee.com 

成功

The authenticity of host 'gitee.com (<Your Server ip>)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9****.
ECDSA key fingerprint is MD5:27:e5:d3****.
Are you sure you want to continue connecting (yes/no)? yes  #第一次需要输入 yes
Warning: Permanently added 'gitee.com,<Your Server ip>' (ECDSA) to the list of known hosts.
Hi ABin(@ABin)! You've successfully authenticated, but GITEE.COM does not provide shell access.

SSH配置公钥无需密码连接服务器Git配置SSH

0

评论区