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

一、首先准备两台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.hqwc.cn/news/154576.html

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

相关文章

38基于matlab的期货预测,利用PSO优化SVM和未优化的SVM进行对比,得到实际输出和期望输出结果。

基于matlab的期货预测,利用PSO优化SVM和未优化的SVM进行对比,得到实际输出和期望输出结果。线性核函数、多项式、RBF核函数三种核函数任意可选,并给出均方根误差,相对误差等结果,程序已调通,可直接运行。 3…

【CSS】CSS 属性计算过程

1. 概述 我们所书写的任何一个 HTML 元素&#xff0c;实际上都有完整的一整套 CSS 样式。如果没有修改某样式&#xff0c;大概率可能使用默认值。 例如&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"&…

【C语言初学者周冲刺计划】1.1用筛选法求100之内的素数

目录 1解题思路&#xff1a; 2代码如下&#xff1a; 3运行代码如图所示&#xff1a; 4总结&#xff1a; (前言周冲刺计划:周一一个习题实操&#xff0c;依次类推加一&#xff0c;望各位读者可以独自实践敲代码) 1解题思路&#xff1a; 首先了解筛选法定义&#xff1a;先把…

人到中年应该怎么交朋友

听人劝、吃饱饭,奉劝各位小伙伴,不要订阅该文所属专栏。 作者:不渴望力量的哈士奇(哈哥),十余年工作经验, 跨域学习者,从事过全栈研发、产品经理等工作,现任研发部门 CTO 。荣誉:2022年度博客之星Top4、博客专家认证、全栈领域优质创作者、新星计划导师,“星荐官共赢计…

PTA 病毒溯源(树)

题目 病毒容易发生变异。某种病毒可以通过突变产生若干变异的毒株&#xff0c;而这些变异的病毒又可能被诱发突变产生第二代变异&#xff0c;如此继续不断变化。 现给定一些病毒之间的变异关系&#xff0c;要求你找出其中最长的一条变异链。 在此假设给出的变异都是由突变引起…

AntDB数据库荣获 “2023年信创物联网优秀服务商”

日前&#xff0c;在2023世界数字经济大会暨第十三届智博会 2023京甬信创物联网产融对接会上&#xff0c;AntDB数据库再获殊荣&#xff0c;获评“2023年信创物联网优秀服务商”。 图1&#xff1a;2023年信创物联网优秀服务商颁奖现场 信创物联网是信息技术应用创新与物联网的结…

DIY相机(一)libcamera库

相机选型 DIY相机首先是要确定使用的相机型号。兼容树莓派&#xff0c;画质好一些的&#xff0c;目前主要有两款&#xff1a;一是Raspberry Pi Camera Module 3&#xff0c;二是Raspberry Pi HQ Camera。 下图是Raspberry Pi Camera Module 3的相关特性。支持自动对焦和HDR等…

【算法|动态规划No30】leetcode5. 最长回文子串

个人主页&#xff1a;兜里有颗棉花糖 欢迎 点赞&#x1f44d; 收藏✨ 留言✉ 加关注&#x1f493;本文由 兜里有颗棉花糖 原创 收录于专栏【手撕算法系列专栏】【LeetCode】 &#x1f354;本专栏旨在提高自己算法能力的同时&#xff0c;记录一下自己的学习过程&#xff0c;希望…

回文链表Java

我们可以采用双指针的办法进行,如下图: 如果链表长度为偶数,则直接从第二个指针的位置开始对链表进行反转;如果是奇数,则从第二指针的下一位进行链表反转 代码实现: public static void main(String[] args) {ListNode next4 new ListNode(1, null);ListNode next3 new Lis…

C++ 自引用指针this(整理)

使用例子&#xff1a; #include <iostream> #include <Windows.h> using namespace std; class A { public:A(int x1){x x1;}void disp(){cout<<"this"<<this<<" when x"<<this->x<<endl;} private:int x;…

【Java数据结构重点知识】第一节:认识数据结构与算法、集合框架

一&#xff1a;数据结构与算法 1.数据结构 数据结构是计算机存储、组织数据的方式&#xff0c;指相互之间存在一种或多种特定关系的数据元素的集合 2.算法 算法就是定义良好的计算过程。他取一个或一组的值为输入&#xff0c;并产生一个或一组作为输出。简单来说就是一系列的…

公司电脑禁用U盘的方法

公司电脑禁用U盘的方法 安企神U盘管理系统下载使用 在这个复杂的数据时代&#xff0c;保护公司数据的安全性至关重要。其中&#xff0c;防止未经授权的数据泄露是其中的一个关键环节。U盘作为一种常用的数据传输工具&#xff0c;也成为了潜在的安全风险。因此&#xff0c;公司…