Linux RHCE练习之远程连接服务实战

Linux RHCE练习之远程连接服务实战

要求

主机一

  • 主机名:server.example.com
  • ip: 172.25.254.100
  • 建立用户timinglee,其密码为timinglee

主机二

  • 主机名:client.example.com
  • ip: 172.25.254.200

实现

主机一实现

[root@server100 ~]# hostnamectl hostname server.example.com
[root@server100 ~]# hostname
server.example.com
[root@server100 ~]# ifconfig | tr -s " " | grep broadcast | cut -d " " -f3
172.25.254.100
[root@server100 ~]# useradd timinglee
[root@server100 ~]# echo "timinglee" | passwd timinglee --stdin
Changing password for user timinglee.
passwd: all authentication tokens updated successfully.
[root@server100 ~]# tail -1 /etc/passwd
timinglee:x:1001:1001::/home/timinglee:/bin/bash

主机二实现

[root@server200 ~]# hostnamectl hostname client.example.com
[root@server200 ~]# hostname
client.example.com
[root@server200 ~]# ifconfig | tr -s " " | grep broadcast | cut -d " " -f3
172.25.254.200

# 免密登录设置
# 使用非交互式设置,并且指定加密算法为rsa算法
[root@server200 ~]# ssh-keygen -f /root/.ssh/id_rsa -P "" -t rsa
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
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:RhwHxNxgpVwJd39BZUncyKIG2QDKyv5JnxBd7Mjrsu0 root@client.example.com
The key's randomart image is:
+---[RSA 3072]----+
|      .=OX=...+=*|
|   . . ==*+...o+o|
|    o   B. . .. .|
| . . o =  o    . |
|  o . + S.       |
| .   . o         |
|  . o .          |
|   o.* .         |
|    ++E          |
+----[SHA256]-----+

# 查看是否生成公私密钥对
[root@server200 ~]# cd /root/.ssh/
[root@server200 .ssh]# ls
id_rsa  id_rsa.pu

# 向主机一的root账户上传本地公钥
[root@server200 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.100 (172.25.254.100)' can't be established.
ED25519 key fingerprint is SHA256:7v4Yn0h5gqnR0kmEQJPtc9vLb4JZmmHL7CBz5aqco+o.
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@172.25.254.100's password:

Number of key(s) added: 1

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

# 向主机一的timinglee账户上传本地公钥
[root@server200 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub timinglee@172.25.254.100
/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
timinglee@172.25.254.100's password:

Number of key(s) added: 1

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

设置只能root用户和timinglee用户可以被登录

需要在主机一操作

# 修改sshd主配置文件

[root@server ~]# vim /etc/ssh/sshd_config

# 修改内容如下:
PasswordAuthentication yes
# 添加一行内容,添加白名单
allowusers root timinglee

# 重启sshd服务
[root@server ~]# systemctl restart sshd

测试是否可以免密连接

# 查看在主机一root账户中是否存在主机二上传的公钥
[root@server .ssh]# cd /root/.ssh/
[root@server .ssh]# ls
authorized_keys

# 查看在主机一timinglee账户中是否存在主机二上传的公钥
[timinglee@server ~]$ cd /home/timinglee/.ssh/
[timinglee@server .ssh]$ ls
authorized_keys

# root账户直接免密连接100的主机
[root@client ~]# ssh -l root 172.25.254.100
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: Fri Apr 19 20:57:54 2024 from 172.25.254.1
[root@server ~]#

# timinglee账户直接免密连接100的主机
[root@client ~]# ssh -l timinglee 172.25.254.100
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: Fri Apr 19 20:58:41 2024
[timinglee@server ~]$s

测试是否只能root用户和timinglee用户可以被登录

# 在主机一添加test用户用来测试
[root@server ~]# useradd test
[root@server ~]# echo "test" | passwd test --stdin
Changing password for user test.
passwd: all authentication tokens updated successfully.

# 在主机二中使用test账户上传公钥至主机一
[root@client ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub test@172.25.254.100
/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
test@172.25.254.100's password:

Number of key(s) added: 1

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

# 测试root和timinglee账户是否可以免密登录主机一
[root@client ~]# ssh root@172.25.254.100
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: Fri Apr 19 21:26:38 2024 from 172.25.254.1
# root账户免密登录成功

# [root@client ~]# ssh timinglee@172.25.254.100
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: Fri Apr 19 21:01:39 2024 from 172.25.254.200

# timinglee账户免密登录成功

# 测试test测试账户是否可以免密登录主机一

[root@client ~]# ssh test@172.25.254.100
test@172.25.254.100's password:
Permission denied, please try again.
test@172.25.254.100's password:

# test账户免密登录主机一失败,因为设置了sshd白名单,只用在白名单的root和timinglee账户可以免密登录主机一

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【工厂模式】工厂方法模式、抽象工厂模式-简单例子

简单工厂模式,请跳转到我的另一篇博客【工厂模式】简单工厂模式-简单例子-CSDN博客 四、工厂方法模式 (1)这部分还是不变,创建一个Car接口,和两个实现类。 public interface Car {void name(); }public class WuLing…

深入刨析 mysql 底层索引结构B+树

文章目录 前言一、什么是索引?二、不同索引结构对比2.1 二叉树2.2 平衡二叉树2.3 B-树2.4 B树 三、mysql 的索引3.1 聚簇索引3.2 非聚簇索引 前言 很多人看过mysql索引的介绍:hash表、B-树、B树、聚簇索引、主键索引、唯一索引、辅助索引、二级索引、联…

C#语法知识之循环语句

5、循环语句 文章目录 1、while思考1 斐波那契数列思考2 判断一个数是否为质数思考3 找出100以内的质数 2、do...while3、for思考1 找水仙花数思考2 乘法表 1、while 1、作用 让代码重复去执行 2、语法相关 while(bool类型值){//当满足条件时,就会执行while语句…

大话设计模式-里氏代换原则

里氏代换原则(Liskov Substitution Principle,LSP) 概念 里氏代换原则是面向对象设计的基本原则之一,由美国计算机科学家芭芭拉利斯科夫(Barbara Liskov)提出。这个原则定义了子类型之间的关系&#xff0…

linux下使用qt+mpv调用GPU硬件解码

linux下GPU硬件解码接口,常用的有vdpau和vaapi。 mpv是基于mplayer开发的一个播放器。此外,mpv还提供了函数库libmpv,通过使用libmpv可以编写一个简单的播放器。 基于qtlibmpv的demo,官方例子代码如下:https://github.…

Java maven项目打包自动测试并集成jacoco生成代码测试覆盖度报告

引入Junit 引入 junit5 单元测试依赖 <properties><junit.version>5.10.2</junit.version><jacoco.version>0.8.12</jacoco.version></properties><dependencies><!-- 单元测试 --><dependency><groupId>org.jun…

JUC 线程间通信

前言 本篇文章我将解释《并发编程的艺术》一书中一个经典的实现线程间通信的案例&#xff0c;主要是使用wait() 和 notifyAll() 方法来实现的。 这段代码的作用是通过 wait() 和 notifyAll() 方法实现线程间的等待和通知机制。具体来说&#xff0c;代码中创建了两个线程&…

论文阅读-Multiple Targets Directed Greybox Fuzzing (Hongliang Liang,2024)

标题: Multiple Targets Directed Greybox Fuzzing (Hongliang Liang,2024) 作者: Hongliang Liang, Xinglin Yu, Xianglin Cheng, Jie Liu, Jin Li 期刊: IEEE Transactions on Dependable and Secure Computing 研究问题: 发现局限性&#xff1a;之前的定向灰盒测试在有…

webAssembly学习及使用rust

学习理解 webAssembly 概念知识&#xff0c;使用 API 进行 web 前端开发。 概念 是一种运行在现代网络浏览器中的新型代码&#xff0c;并且提供新的性能特性和效果。它有一种紧凑的二进制格式&#xff0c;使其能够以接近原生性能的速度运行。C/C、 C#、Rust等语言可以编译为 …

ruby 配置代理 ip(核心逻辑)

在 Ruby 中配置代理 IP&#xff0c;可以通过设置 Net::HTTP 类的 Proxy 属性来实现。以下是一个示例&#xff1a; require net/http// 获取代理Ip&#xff1a;https://www.kuaidaili.com/?refrg3jlsko0ymg proxy_address 代理IP:端口 uri URI(http://www.example.com)Net:…

【React】Sigma.js框架网络图-入门篇

一、介绍 Sigma.js是一个专门用于图形绘制的JavaScript库。 它使在Web页面上发布网络变得容易&#xff0c;并允许开发人员将网络探索集成到丰富的Web应用程序中。 Sigma.js提供了许多内置功能&#xff0c;例如Canvas和WebGL渲染器或鼠标和触摸支持&#xff0c;以使用户在网页上…

MATLAB R2024a:重塑商业数学软件的未来

在数字化浪潮席卷全球的今天&#xff0c;商业数学软件已经成为企业、研究机构乃至个人不可或缺的工具。而在这其中&#xff0c;MATLAB R2024a以其卓越的性能和广泛的应用领域&#xff0c;正逐步成为商业数学软件的新标杆。 MATLAB R2024a不仅继承了前代版本的优秀基因&#xf…

Golang 采集爬虫如何配置代理 IP

在 Golang 中配置代理 IP&#xff0c;可以通过设置 http.Transport 的 Proxy 属性来实现&#xff1a; 下述代码中的 代理IP 和 端口 替换为实际的代理服务器地址和端口&#xff0c;然后运行该程序即可通过代理服务器访问对应网站。 package mainimport ("fmt""…

超详细的Maven安装与使用还有内容讲解

文章目录 作用简介模型仓库 安装配置IDEA配置Maven坐标概念主要组成 IDEA创建Maven项目基本使用常用命令生命周期使用坐标导入jar包 注意事项清理maven仓库更新索引依赖 作用 Maven是专门用于管理和构建Java项目的工具&#xff0c;它的主要功能有&#xff1a; 提供了一套标准化…

MATLAB实现禁忌搜索算法优化柔性车间调度fjsp

禁忌搜索算法的流程可以归纳为以下几个步骤&#xff1a; 初始化&#xff1a; 利用贪婪算法或其他局部搜索算法生成一个初始解。清空禁忌表。设置禁忌长度&#xff08;即禁忌表中禁止操作的期限&#xff09;。邻域搜索产生候选解&#xff1a; 通过特定的搜索算子&#xff08;如…

AWS账号注册以及Claude 3 模型使用教程!

哈喽哈喽大家好呀&#xff0c;伙伴们&#xff01;你听说了吗&#xff1f;最近AWS托管了大热模型&#xff1a;Claude 3 Opus&#xff01;想要一探究竟吗&#xff1f;那就赶紧来注册AWS账号吧&#xff01;别担心&#xff0c;现在注册还免费呢&#xff01;而且在AWS上还有更多的大…

【北京迅为】《iTOP-3588开发板系统编程手册》-第10章 存储映射 I/O

RK3588是一款低功耗、高性能的处理器&#xff0c;适用于基于arm的PC和Edge计算设备、个人移动互联网设备等数字多媒体应用&#xff0c;RK3588支持8K视频编解码&#xff0c;内置GPU可以完全兼容OpenGLES 1.1、2.0和3.2。RK3588引入了新一代完全基于硬件的最大4800万像素ISP&…

Spark-Scala语言实战(17)

我带着大家一起来到Linux集群环境下&#xff0c;学习我们的spark。想了解的朋友可以查看这篇文章。同时&#xff0c;希望我的文章能帮助到你&#xff0c;如果觉得我的文章写的不错&#xff0c;请留下你宝贵的点赞&#xff0c;谢谢。 Spark-Scala语言实战&#xff08;16&#x…

基于Springboot的社区帮扶对象管理系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的社区帮扶对象管理系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系…

微信小程序日期增加时间完成订单失效倒计时(有效果图)

效果图 .wxml <view class"TimeSeond">{{second}}</view>.js Page({data: {tiem_one:,second:,//倒计时deadline:,},onLoad(){this.countdown();},countdown(){let timestamp Date.parse(new Date()) / 1000;//当前时间戳let time this.addtime(2024…