如何实现两台Linux虚拟机ssh免密登录

实验开始前

1.准备好两台虚拟机(下载好镜像文件的)

2.实验步骤

公钥验证:(免密登陆验证方式)
(1)生成非对称秘钥
[root@client ~]# ssh-keygen  -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:i8wSE5j8P2yxx8tsfkgkG+VBCDBfuW4Y5UdDpMq9cd4 root@client
The key's randomart image is:
+---[RSA 3072]----+
|  o....*+        |
| . = .+.=        |
|  + oo.= o       |
|   o.+= +        |
|    *++*S        |
|    .B+X.o       |
|    ..@.=.E      |
|     o =o..      |
|       o=.       |
+----[SHA256]-----+
(2) 公钥发送到服务器/root/.ssh/authorized_keys
[root@client ~]# ssh-copy-id -i root@192.168.10.129
(3) 等待客户端请求内部通过非对称验证
[root@client ~]# ssh root@192.168.10.129

 以上是实验步骤,下面是具体操作:

可以在VMware里面操作,也可以用Xshell,我这里用的是MobaXterm

 

1. 我这里先将虚拟机名字改了(方便看是否连接上)

这里客户端IP为192.168.168.129

服务器的IP为192.168.168.128

2. 生成非对称秘钥

ssh-keygen  -t rsa

3. 公钥发送到服务器/root/.ssh/authorized_keys

[root@client ~]# ssh-copy-id  192.168.10.129

4.  等待客户端请求内部通过非对称验证

[root@client ~]# ssh 192.168.10.129

[root@client ~]# #先改名虚拟机名字,方便查看是否连接上(必须永久保存名字,不然没用)
[root@client ~]# hostnamectl set-hostname client
[root@client ~]# #再生成非对称密钥
[root@client ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:NHG9KayVObJloLgIlK+urlFYJkYzTUJ7BcBd1rs1lhw root@client
The key's randomart image is:
+---[RSA 3072]----+
|oB*oo+. . ..     |
|.+=oo  ..E  .    |
|oo+. . .=ooo o   |
|o=... .o.BX o    |
|..o. .  SB.o     |
| o. .  .o        |
|o                |
| o               |
|*.               |
+----[SHA256]-----+

 然后再将公钥发送给服务器(IP地址):

注意这里输完:[root@client ~]# ssh-copy-id  192.168.10.129这个命令后,会让你输入yes还是no

[root@client ~]# #然后再将公钥发送给另外一个虚拟机(服务器)
[root@client ~]# ssh-copy-id 192.168.168.128
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.168.12 (192.168.168.12)' can't be established.
ED25519 key fingerprint is SHA256:t9VyyGfB3e3ltZhQPNA27vzQt4OVzyYielt8R9SI8Ho.
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.168.128's password:Number of key(s) added: 1Now try logging into the machine, with:   "ssh '192.168.168.128'"
and check to make sure that only the key(s) you wanted were added.

然后服务器配置也是一样的操作:

[root@server ~]# hostnamectl set-hostname server
[root@server ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:t7DsCVsPfihjwFagBdeqWxLXIXUp+pzwMAWs+muSnzI root@server
The key's randomart image is:
+---[RSA 3072]----+
|  .oo+. ..       |
|   .= =..        |
|   + B o         |
|  + B o          |
| . = O .S .      |
|. o = =. + .     |
| o = .. =..      |
|E +.  +*.+.      |
| *+. ..o+..      |
+----[SHA256]-----+
[root@server ~]# ssh-copy-id 192.168.168.129
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.168.129 (192.168.168.129)' can't be established.
ED25519 key fingerprint is SHA256:t9VyyGfB3e3ltZhQPNA27vzQt4OVzyYielt8R9SI8Ho.
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.168.129's password:Number of key(s) added: 1Now try logging into the machine, with:   "ssh '192.168.168.129'"
and check to make sure that only the key(s) you wanted were added.

最后验证:

直接输入ssh  +  IP地址

客户端到服务器:

 服务器到客户端:

 可以看到输完ssh后,直接登录进去了,免密登录,实验就完成了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/611590.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2024华数杯国际大学生数学建模思路+模型+代码+论文

2024年第二届“华数杯”国际大学生数学建模竞赛 赛题思路模型代码论文:开赛后第一时间更新,文末名片获取 竞赛信息 一、比赛背景 2024年第二届“华数杯”国际大学生数学建模竞赛(以下简称“竞赛”)是天津市未来与预测科学研究会…

秒变办公达人,只因用了这5款在线协同文档app!

在日常工作中,我们不可避免地需要处理各种文档,有时你可能会为如何高效地管理这些文档而感到烦恼,或是不知道如何挑选合适的在线文档工具? 不用担心!在这篇文章中,我们将介绍5个好用的在线文档工具App&…

SpringBoot+Hutool实现图片验证码

图片验证码在注册、登录、交易、交互等各类场景中都发挥着巨大作用,能够防止操作者利用机器进行暴力破解、恶意注册、滥用服务、批量化操作和自动发布等行为。 创建一个实体类封装,给前端返回的验证码数据: Data public class ValidateCodeV…

一、数据结构基本概念

数据结构基本概念 一、数据结构基本概念1.基本概念和术语1.1数据(Data)1.2 数据元素(Data element)1.3 数据项 (Data Item)1.4 数据对象 (Data Object)1.5 数据结构 (Dat…

基于 Validator 类实现 ParamValidator,用于校验函数参数

目录 一、前置说明1、总体目录2、相关回顾3、本节目标 二、操作步骤1、项目目录2、代码实现3、测试代码4、日志输出 三、后置说明1、要点小结2、下节准备 一、前置说明 1、总体目录 《 pyparamvalidate 参数校验器,从编码到发布全过程》 2、相关回顾 使用 TypeV…

Every Nobody Is Somebody 「每小人物都能成大事」

周星驰 NFT Nobody即将发售,Nobody共创平台 Every Nobody Is Somebody Nobody 关于Nobody:Nobody是一款Web3共创平台,旨在为创作者提供一个交流和合作的场所,促进创意的产生和共享。通过该平台,创作者可以展示自己的作…

git秘钥过期 ERROR: Your SSH key has expired

文章目录 1、错误提示Your SSH key has expired2、登录Github确认3、重新设置秘钥 1、错误提示Your SSH key has expired 使用git命令时遇到Github 的 SSH Key秘钥过期,提示错误ERROR: Your SSH key has expired 2、登录Github确认 首先登录Github查看&#xff…

L1-015 跟奥巴马一起画方块(Java)

美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在…

某查查请求头参数加密分析(含JS加密算法与Python爬虫源码)

文章目录 1. 写在前面2. 请求分析3. 断点分析4. 扣加密JS5. Python爬虫代码实现 【作者主页】:吴秋霖 【作者介绍】:Python领域优质创作者、阿里云博客专家、华为云享专家。长期致力于Python与爬虫领域研究与开发工作! 【作者推荐】&#xff…

基于SELinux三权分立配置方法

1.系统安装 系统安装完成后,系统当前的SELinux配置为: # cat /etc/selinux/config SELINUX=enforcing SELINUXTYPE=targeted 2.SELinux环境准备 # yum install setools policycoreutils.x86_64 selinux-policy-mls.noarch setroubleshoot.x86_64 setools-console -y 3.SELin…

嵌入式c语言学习笔记:可重入函数与不可重入函数

什么是可重入函数与不可重入函数? 在一个多任务环境中,一个函数如果可以被多次重复调用,或者被多个任务并发调用,函数在运行过程中可以随时随地被打断,并不影响该函数的运行结果,我们称这样的函数为可重入…

Redis 常用的数据类型及用法

1. 字符串(Strings) 字符串是最基本的 Redis 数据类型。它可以包含任何形式的数据,比如文本、数字或二进制数据。 基本用法: 设置值: SET key value获取值: GET key删除键: DEL key自增: INCR key追加值: APPEND key value 示…

vue element plus TimePicker 时间选择器

用于选择或输入日期 TIP 在 SSR 场景下&#xff0c;您需要将组件包裹在 <client-only></client-only> 之中 (如: Nuxt) 和 SSG (e.g: VitePress). 任意时间点# 可以选择任意时间 提供了两种交互方式&#xff1a;默认情况下通过鼠标滚轮进行选择&#xff0c;打开…

三、java线性表(顺序表、链表、栈、队列)

java线性表 三、线性表1.1 顺序表1.2 链表1.2.1 单向链表&#xff08;Singly Linked List&#xff09;1.2.2 双向链表&#xff08;Doubly Linked List&#xff09; 1.3 LinkedList VS ArrayList1.3.7 使用 LinkedList 的场景 1.4 栈1.5 队列 三、线性表 线性表是一种经典的数据…

LeetCode2696. Minimum String Length After Removing Substrings

文章目录 一、题目二、题解 一、题目 You are given a string s consisting only of uppercase English letters. You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings “AB” or “CD” from s…

手撕单链表(单向,不循环,不带头结点)的基本操作

&#x1d649;&#x1d65e;&#x1d658;&#x1d65a;!!&#x1f44f;&#x1f3fb;‧✧̣̥̇‧✦&#x1f44f;&#x1f3fb;‧✧̣̥̇‧✦ &#x1f44f;&#x1f3fb;‧✧̣̥̇:Solitary-walk ⸝⋆ ━━━┓ - 个性标签 - &#xff1a;来于“云”的“羽球人”。…

mercury靶机

文章妙语 不与伪君子争名&#xff0c;不与真小人争利&#xff0c;不与执拗人争理&#xff0c;不与匹夫争勇&#xff0c;不与酸儒争才。不与蠢人施恩 一、信息收集 主机探测 端口探测 探测主机详细版本信息 8080开了http服务 目录扫描 robots.txt目录下什么也没有 二&#xff0…

Python | Iter/genartor | 一文了解迭代器、生成器的含义\区别\优缺点

前提 一种技术的出现&#xff0c;需要考虑&#xff1a; 为了实现什么样的需求&#xff1b;遇到了什么样的问题&#xff1b;采用了什么样的方案&#xff1b;最终接近或达到了预期的效果。 概念 提前理解几个概念&#xff1a; 迭代 我们经常听到产品迭代、技术迭代、功能迭代…

oracle常用内部表和视图

Oracle数据库中存在大量内部表和视图&#xff0c;主要用于系统管理和维护。这里列出一些常用的内部视图&#xff08;数据字典视图&#xff09;和内部表&#xff1a; **常用内部视图&#xff08;Data Dictionary Views&#xff09;&#xff1a;** 1. **用户权限相关视图&#…

零基础学习数学建模——(二)数学建模的步骤

本篇博客将详细介绍数学建模的步骤。 文章目录 引例&#xff1a;年夜饭的准备第一步&#xff1a;模型准备第二步&#xff1a;模型假设第三步&#xff1a;模型建立第四步&#xff1a;模型求解第五步&#xff1a;结果分析第六步&#xff1a;模型检验第七步&#xff1a;模型应用及…