【摘要】SSH登录是用的RSA非对称加密的,所以我们在SSH登录的时候就可以使用RSA密钥登录,SSH有专门创建SSH密钥的工具ssh-keygen
首先进入Linux系统(本机IP:192.168.229.128)的用户目录下的.ssh目录下,root用户是/root/.ssh,普通用户是/home/您的用户名/.ssh,我们以root用户为例:
注:.ssh 是记录密码信息的文件夹,如果没有登录过root的话,就没有 .ssh 文件夹,因此登录 localhost ,并输入密码就会生成了
[root@localhost sxl]# ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:vSFOJEj50ukE6RaNuwel4Oqkkrow15CrIl7IWYyBHPU.
ECDSA key fingerprint is MD5:5e:fa:59:7a:4d:cd:9d:22:b9:47:4b:4f:e5:e5:0c:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
root@localhost's password:
Last failed login: Thu Feb 24 04:08:49 PST 2022 from localhost on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Thu Feb 24 04:05:17 2022 from 192.168.229.1
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ll
total 4
-rw-r--r-- 1 root root 171 Feb 24 04:08 known_hosts
[root@localhost .ssh]#
一、 可以先看看目录下,没有进行过ssh密钥创建的样子如下
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ll
total 4
-rw-r--r-- 1 root root 171 Feb 24 04:08 known_hosts
[root@localhost .ssh]#
二、 执行ssh-keygen命令创建密钥对
加了-b 参数,指定了长度,也可以不加-b参数,直接使用ssh-keygen -t rsa,ssh-keygen命令的参数后文会有介绍。
执行密钥生成命令,基本上是一路回车既可以了,但是需要注意的是:执行命令的过程中是会提示呢输入密钥的密码的,不需要密码直接回车就行。
[root@localhost .ssh]# ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase