Liunx两台服务器实现相互SSH免密登录

news2024/10/6 20:39:58

一、首先准备两台Linux虚拟机当作此次实验的两台服务器

服务器1:server        IPV4:192.168.110.136

服务器2:client         IPV4: 192.168.110.134

二、准备阶段

[root@server ~]# systemctl disable firewalld          #关闭防火墙

[root@server ~]# setenforce  0                                   #关闭seLiunx

[root@server ~]# getenforce

Permissive

[root@client ~]# systemctl disable firewalld          #关闭防火墙

[root@client ~]# setenforce  0                                   #关闭seLiunx

[root@client ~]# getenforce

Permissive

三、配置

server免密访问client

[root@server ~]# ssh-keygen -t rsa                                #此处为rsa密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:EtRb4lrkGMtSaa+JoG3bL2AfzUlJPbx114ZZyOmOf04 root@server
The key's randomart image is:
+---[RSA 3072]----+
|              .=     . B.  |
|          .* B o . B o  |
|          =.X B . o .   |
|          . . *.B     .    |
|       o . *.*S    o    |
|.       = o B.    . .    |
|       o = .       .  E  |
|          . +         ...  |
|            o.        o.  |
+----[SHA256]-----+

[root@server ~]# ll /root/.ssh/                                 #查看密钥匙目录
总用量 8
-rw-------. 1 root root 2590 10月 26 22:40 id_rsa               #私钥文件
-rw-r--r--. 1 root root  565 10月 26 22:40 id_rsa.pub         #公钥文件

[root@server ~]# ssh-copy-id root@192.168.110.134  #复制该公钥文件到服务端的该目录下
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.110.134 (192.168.110.134)' can't be established.
ED25519 key fingerprint is SHA256:rFpTMCYeFtLw16vHvNCtD7f+AutcLz68mnrlopUfino.
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.110.134's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.110.134'"
and check to make sure that only the key(s) you wanted were added.

在client端查看文件

[root@client ~]# ll /root/.ssh/
总用量 4
-rw-------. 1 root root 565 10月 26 22:46 authorized_keys

[root@server ~]# ssh 192.168.110.134                 #使用SSH远程登录client

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: Thu Oct 26 22:33:54 2023 from 192.168.110.1

[root@client ~]# 

免密登陆成功!!!

client免密访问server

[root@client ~]# ssh-keygen -t rsa                #此处为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:mmA+3Ih66Ue7yv1TBdvjbcsmmTKeK7U9rBEuW1NWOiU root@client
The key's randomart image is:
+---[RSA 3072]----+
|                            |
|        .                   |
|         +E o           |
|        . +=             |
|    o   So=o         |
|   =.+ +o+..o       |
|  .o=.=o=+ = .     |
| oo.o.o+++B +    |
|.o+oooo+== +    |
+----[SHA256]-----+

[root@client ~]# ll /root/.ssh/                #查看密钥匙目录
总用量 20
-rw-------. 1 root root  565 10月 26 22:46 authorized_keys  #server免密访问client生成的密钥
-rw-------. 1 root root 2590 10月 26 22:57 id_rsa                      #私钥文件
-rw-r--r--. 1 root root  565 10月 26 22:57 id_rsa.pub                 #公钥文件
-rw-------. 1 root root  843 10月 26 22:57 known_hosts              #记录服务端发来的公钥信息
-rw-r--r--. 1 root root   97 10月 26 22:57 known_hosts.old    #储之前连接过的 SSH 服务器的公钥

[root@client ~]# ssh-copy-id root@192.168.110.136    #复制该公钥文件到服务端的该目录下
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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.110.136's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.110.136'"
and check to make sure that only the key(s) you wanted were added.

在server端查看文件

[root@server ~]# ll /root/.ssh/
总用量 20
-rw-------. 1 root root  565 10月 26 23:01 authorized_keys
-rw-------. 1 root root 2590 10月 26 22:40 id_rsa
-rw-r--r--. 1 root root  565 10月 26 22:40 id_rsa.pub
-rw-------. 1 root root  843 10月 26 22:46 known_hosts
-rw-r--r--. 1 root root   97 10月 26 22:46 known_hosts.old

[root@client ~]# ssh 192.168.110.136         #使用SSH远程登录server
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: Thu Oct 26 22:57:34 2023 from 192.168.110.134

[root@server ~]# 

登陆成功!!!

实验结束实现服务器1server和服务器2client相互免密登录!

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

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

相关文章

【MySQL索引与优化篇】InnoDB数据存储结构

文章目录 1. 数据库的存储结构:页1.1 磁盘与内存交互基本单位:页1.2 页结构概述1.3 页的上层结构 2. 页的内部结构3. InnoDB行格式(或记录格式)3.1 Compact行格式3.2 Dynamic和Compressed行格式3.3 Redundant行格式 4. 区、段与碎片区4.1 为什么要有区?4.2 为什么要…

Webpack简介及打包演示

Webpack 是一个静态模块打包工具,从入口构建依赖图,打包有关的模块,最后用于展示你的内容 静态模块:编写代码过程中的,html,css, js,图片等固定内容的文件 打包过程,注…

【iOS安全】提取app对应的URLScheme

获取app的URLScheme 在已越狱的iPhone上,使用Filza进入app列表目录: /private/var/containers/Bundle/Application/ 比如我要分析Microsoft Authenticator,明显对应的是这里面的“Authenticator”,那就在Filza中点击进入“Authen…

网络协议--TFTP:简单文件传送协议

15.1 引言 TFTP(Trivial File Transfer Protocol)即简单文件传送协议,最初打算用于引导无盘系统(通常是工作站或X终端)。和将在第27章介绍的使用TCP的文件传送协议(FTP)不同,为了保持简单和短小&#xff0…

STM32中断,看着一篇就够了

1,环境搭建: 硬件平台:STM32H750XBH6 开发环境:STM32CubeMX V6.8.1KEIL V5.28.0.0 STM32H750固件版本:package V1.11.0 仿真下载驱动:ST-Link 2,中断的定义 中断(Interrupt&#xff…

【考研数学】数学“背诵”手册 | 需要记忆且容易遗忘的知识点

文章目录 引言一、高数常见泰勒展开 n n n 阶导数公式多元微分函数连续、可微、连续可偏导之间的关系多元函数极值无条件极值条件极值 三角函数的积分性质华里士公式( “点火”公式 )特殊性质 原函数与被积函数的奇偶性结论球坐标变换公式 二、写在最后 …

centos中安装mysql5.7

建议第八步骤,和第九步骤对于生产者人员就不用配置了,风险大,我自己的也没有配置 1.首先切换到root用户下 2.更新密钥 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 3.安装mysql yum库 rpm -Uvh https://repo.mysql.com//…

云计算模式的区域LIS系统源码,基于ASP.NET+JQuery、EasyUI+MVC技术架构开发

云计算模式的区域LIS系统源码 云LIS系统源码,自主版权 LIS系统是专为医院检验科的仪器设备能与计算机连接。可通过LIS系统向仪器发送指令,让仪器自动操作和接收仪器数据。并快速的将检验仪器中的数据导入到医生工作站中进行管理,且可将检验结…

10.26ALP论文原代码请稿

尊敬的作者, 我是中国重庆大学的一名学生,近期准备就浮点数据无损压缩这个研究领域作一篇综述。 我对于您的ALP压缩算法十分感兴趣,并对于它的表现感到十分惊喜,我自己也尝试按您文章里的伪代码与思路复现您的方法,但…

非小米笔记本小米妙享中心安装最新教程 3.2.0.464 兼容所有Windows系统

小米妙享中心 3.2.0.464 版本帮助 : 支持音频流转、屏幕镜像、屏幕拓展、键鼠拓展、无线耳机、小米互传 目录 小米妙享中心 3.2.0.464 版本帮助 : 1.常规教程使用安装包方式安装失败 或者 1.1安装失败可使用大佬的加载补丁方法解决 补充卸载残留 1.2 截图存档 2. 本教程…

CentOS - 安装 Elasticsearch

"Elasticsearch"是一个流行的开源搜索和分析引擎,它可以用于实时搜索、日志和事件数据分析等任务。以下是在 CentOS 上安装 Elasticsearch 的基本步骤: 安装 Java: Elasticsearch 是基于 Java 的应用程序,所以首先需要…

Git窗口打开vim后如何退出编辑(IDEA/Goland等编辑器)

最近在学习git高级操作过程中,遇到了一下问题: 我在学习Git合并多个commit为一个的时候,需要输入一个命令 git rebase -i HEAD~2 这说明已经是编辑模式了。当我写好后,我还按照原来在linux上的按下ESC键,但是只是光…

题目 1058: 二级C语言-求偶数和(python详解)——练气四层中期

✨博主:命运之光 🦄专栏:算法修炼之练气篇(C\C版) 🍓专栏:算法修炼之筑基篇(C\C版) 🍒专栏:算法修炼之练气篇(Python版) ✨…

ThreadLocal 是什么?它的实现原理呢?

这个问题我从三个方面来回答: ThreadLocal 是一种线程隔离机制,它提供了多线程环境下对于共享变量访问的安全性。 在多线程访问共享变量的场景中(出现下面第一个图),一般的解决办法是对共享变量加锁(出现下…

太极v14.0.4 免ROOT用Xposed

一个帮助你免 Root、免解锁免刷机使用 Xposed 模块的 APP 框架。 模块通过它改变系统和应用的行为,既能以传统的 Root/ 刷机方式运作, 也能免 Root/ 免刷机运行;并且它支持 Android 5.0 ~ 11。 简单来说,太极就是个 Xposed 框架…

0基础学习PyFlink——用户自定义函数之UDF

大纲 标量函数入参并非表中一行(Row)入参是表中一行(Row)alias PyFlink中关于用户定义方法有: UDF:用户自定义函数。UDTF:用户自定义表值函数。UDAF:用户自定义聚合函数。UDTAF&…

基于LSTM encoder-decoder模型实现英文转中文的翻译机器

前言 神经网络机器翻译(NMT, neuro machine tranlation)是AIGC发展道路上的一个重要应用。正是对这个应用的研究,发展出了注意力机制,在此基础上产生了AIGC领域的霸主transformer。我们今天先把注意力机制这些东西放一边,介绍一个对机器翻译…

[论文阅读]Point Density-Aware Voxels for LiDAR 3D Object Detection(PDV)

PDV Point Density-Aware Voxels for LiDAR 3D Object Detection 论文网址:PDV 论文代码:PDV 简读论文 摘要 LiDAR 已成为自动驾驶中主要的 3D 目标检测传感器之一。然而,激光雷达的发散点模式随着距离的增加而导致采样点云不均匀&#x…

云原生架构设计理论与实践

云原生架构设计理论与实践 云原生架构概述 云原生的背景 云原生定义和特征 云原生架构的设计原则 架构模式 服务化架构模式 Mesh化架构模式 Serverless模式 存储计算分离模式 分布式事务模式 可观测架构 事件驱动架构 云原生架构相关技术 容器技术 云原生微服务技术 无服务…

orm连接mysql

7.2 ORM ORM可以帮助我们做两件事 创建、修改、删除数据库中的表(不用写SQL语句)。无法创建数据库操作表中的数据(操作表中的数据)。 1.自己创建数据库 启动自己的mysql服务自带的工具创建数据库 create database gx_day5 DE…