ssh-keygen命令生成RSA、ed25519类型密钥对

转载请标明出处:
https://bigmaning.blog.csdn.net/article/details/125567360
本文出自:【BigManing的博客】

一、ssh-keygen作用

ssh-keygen用来生成ssh公钥认证所需的公钥和私钥文件

二、ssh-keygen命令参数

ssh-keygen [选项]

-b:指定密钥长度;

-e:读取openssh的私钥或者公钥文件;

-C添加注释; (一般设置为自己的邮箱)

-f:指定用来保存密钥的文件名;

-i:读取未加密的ssh-v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥;

-l:显示公钥文件的指纹数据;

-N:提供一个新密语;

-P:提供(旧)密语;

-q:静默模式;

-t指定要创建的密钥类型。 (常用参数)

三、ssh-keygen示例

生成的密钥对,默认会生成在用户目录下的.ssh目录下,密钥对格式为id_「密钥类型」 ,例如 私钥:id_rsa 、公钥:id_rsa_pub

1、生成RSA类型密钥对

命令

ssh-keygen -t rsa  -C Bigmaning@qq.com

输出

Generating public/private rsa key pair.

//======> 存储路径  直接回车 使用默认路径
Enter file in which to save the key (/Users/bigmaning/.ssh/id_rsa):

//======> 设置密码  直接回车 默认不设置密码
Enter passphrase (empty for no passphrase):

//======> 确认密码  操作同上(直接回车 默认不设置密码)
Enter same passphrase again:

//======>  生成的密钥对的位置
Your identification has been saved in /Users/bigmaning/.ssh/id_rsa.
Your public key has been saved in /Users/bigmaning/.ssh/id_rsa.pub.

The key fingerprint is:
SHA256:K9eP3Ik0VtCVPJtfsu4Q8UFumumtCnQxCpLMBladBg8 Bigmaning@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|  o.Eo .     .o. |
| . + ++    . ++  |
|    *.o   + o ++ |
|   . . . . + B+..|
|        S . * .+.|
|       . + o o. .|
|      . + = o..  |
|       o = * +.  |
|          =.=..  |
+----[SHA256]-----+

2、生成ed25519类型密钥对

同rsa操作

ssh-keygen -t ed25519  -C Bigmaning@qq.com

四、使用场景

1、github免密push代码

使用ed25519类型密钥对中的公钥,配置到github中。

  1. 登录你的github账号,从又上角的设置( Account Settings )进入,然后点击菜单栏的 SSH key 进入页面添加 SSH key。
  2. 复制id_ed25519.pub 公钥内容
  3. 点击 Add SSH key 按钮添加一个 SSH key 。把你复制的公钥内容粘贴到 key 所对应的输入框中。
    在这里插入图片描述

2、免密登陆远程服务器

嗯 配置OK后,每次登陆远程机器 只需 ssh root@xxx.xxx.xxx.xxx 命令即可,不需要输入密码了

  1. 生成rsa密钥对,比如公钥地址~/.ssh/id_rsa.pub
  2. 复制公钥到远程机器 :ssh-copy-id -i ~/.ssh/id_rsa.pub root@xxx.xxx.xxx.xxx ,这个步骤是需要输入远程服务器密码。
  3. 上步骤成功后,后续 root@xxx.xxx.xxx.xxx 就能直接登陆到远程机器了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值