1.准备两台服务器,配置服务器1免密登录到服务器2, 配置服务器2免密登录到服务器1
服务器1 | 服务器2 |
---|---|
192.168.118.129 | 192.168.118.130 |
1>基础步骤
-
ssh-keygen:用于生成、管理密钥
-
格式
[root@node1 ~]#ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -P '' -q
-
分析
-
-t:指定加密类型
-
rsa:rsa公钥加密算法,可以产生公钥和私钥
-
注意:执行后对应账户目录下的隐藏目录.ssh中有2个文件:
-
/root/.ssh/id_rsa:本机私钥文件
-
/root/.ssh/id_rsa.pub:本机公钥文件
-
-
2>虚拟机之间实现免密登录
-
第一步:定位服务器2端,制作公私对
[root@node1 ~]# ssh-keygen -t rsa # 一路回车即可
-
第二步:定位服务器2端,将公钥上传
[root@node1 ~]# ssh-copy-id root@192.168.118.129 # 将node1公钥上传给130主机
The authenticity of host '192.168.48.130 (192.168.118.129)' can't be established.
ED25519 key fingerprint is SHA256:K7nvJFkfIh+p9YytEGR44wLbTfpB0Y52oVou0UdG6nc.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes #输入
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.118.129's password: # 输入登录密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.118.129'"
and check to make sure that only the key(s) you wanted were added.
-
第三步:服务器1端测试
[root@node1 ~]# ssh root@192.168.118.129
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sun Sep 24 20:48:39 2023 from 192.168.118.1
[root@server ~]#
-
第四步:由于目标是双向免密,只需在服务器1端重复执行同样操作,生成密钥公私对,再将公钥上传给服务器2即可。
-
第五步:测试图展示
2.ssh工作流程分为哪几个阶段
分为5个阶段,具体如下:
过程 | 说明 |
---|---|
版本号协商阶段 | SSH目前包括SSH1和SSH2两个版本,双方通过版本协商确定使用的版本 |
密钥和算法协商阶段 | SSH支持多种加密算法,双方根据本端和对端支持的算法,协商出最终使用的算法 |
认证阶段 | SSH客户端向服务器端发起认证请求,服务器端对客户端进行认证 |
会话请求阶段 | 认证通过后,客户端向服务器端发送会话请求 |
交互会话阶段 | 会话请求通过后,服务器端和客户端进行信息的交互 |
3.ssh工作流程中使用到哪几类加密算法,以及对称加密常用的算法有哪些,非对称加密算法有哪些
-
在SSH工作流程中使用到以下几类加密算法:对称加密算法->用于实际的数据传输过程中加密和解密数据;非对称加密算法->用于SSH连接的密钥交换和身份验证过程中;散列函数->用于生成消息的摘要,以确保数据的完整性;随机数生成算法:用于生成安全的随机数,用于密钥的生成和会话标识符的创建,这些加密算法的使用可以保证在SSH连接中数据的安全传输、身份验证和数据完整性。
-
常见的对称加密 算法主要有 DES、3DES、AES 等
-
常见的非对称算法 主要有 RSA、ECC 、DSA、ECDSA等