当前位置: 首页 > news >正文

RHCE的SSH配置文件及实验

一、ssh的配置文件

# 所有ssh_host开头的文件都是 ssh主机密钥 总共有3对,分时rsa ecdsa ed5519三种非对称加密算法产生的密钥对
[root@server ssh]# ls
moduli              
ssh_host_ecdsa_key.pub
ssh_config       # ssh客户端主配置文件  
ssh_host_ed25519_key
ssh_config.d        # ssh客户端的子配置文件目录(子配置的优先级高于主配置)
ssh_host_ed25519_key.pub
sshd_config         # ssh服务端主配置文件
ssh_host_rsa_key
sshd_config.d       # ssh服务端的子配置文件目录(子配置的优先级高于主配置)
ssh_host_rsa_key.pub
ssh_host_ecdsa_key

1.sshd_config

注意:大多数的服务在修改完配置文件之后都需要重新将服务启动。

# 在世界范围内有一个关于计算机的共识:
# 计算机的0-1024端口是固定的给某些特定的程序使用
# 例:明文web服务他的端口号(http):80 加密web服务端口(https):443
# 远程加密链接协议ssh:22 telnet:23

 21 #Port 22 ssh的专用服务端口
22 #AddressFamily any
23 #ListenAddress 0.0.0.0 ssh监听所有ipv4
24 #ListenAddress ::  ssh监听所有ipv6
25
# 下面这三个文件是 ssh主机私钥保存位置
26 #HostKey /etc/ssh/ssh_host_rsa_key
27 #HostKey /etc/ssh/ssh_host_ecdsa_key
28 #HostKey /etc/ssh/ssh_host_ed25519_key

39 #LoginGraceTime 2m 登录时输入密码市场不能超过2分钟
40 #PermitRootLogin prohibit-password #禁止root使用密码登录

 49 AuthorizedKeysFile      .ssh/authorized_keys # 客户端使用免密登录时,必须将自己的公钥保存在这个文件中,否则无法免密登录

65 #PasswordAuthentication yes 是否允许使用密码登录
66 #PermitEmptyPasswords no 是否允许空密码登陆

110 #ClientAliveInterval 100 # 发送激活包的时间间隔
111 #ClientAliveCountMax 3 # 发送几次激活包

二、实验

1.修改ssh服务器端的端口号 33          

22 Port 33    

2.拒绝root账户远程登录 (不仅仅要修改掉主配置文件,子配置文件的修改才是关键)
# 主配置文件的路径:/etc/sshd/sshd_config
# 子配置文件的路径:/etc/sshd/sshd_config.d/01-permitrootlogin.conf
permitRootLogin yes

3.允许特定账户进行ssh登录,其它账户无法登录

# 在sshd主配置中第一行写下如下内容
AllowUsers redhat #白名单

4.虚拟机之间免密登陆

# 客户端生成非对称加密的密钥对
[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:UJYMV5EgzGVuiFoDjSj/sDN7vkaP9gqgnr1/HmFU5fQ root@client
The key's randomart image is:
+---[RSA 3072]----+
| ..o oo+B=+=     |
|o ....oO+ + .    |
|..  + o.o  . E   |
|  oo ..o         |
|. .+   oS        |
|..+ o . .        |
|. .= o .         |
|. +.= ...        |
| o B*=+.         |
+----[SHA256]-----+

#[root@client .ssh]# ls
# id_rsa 登录密钥的私钥  id_rsa.pub 登录密钥公钥  known_hosts 记录了服务器的主机公钥  known_hosts.old

# 将生成的登录密钥对中公钥发送给服务器
[root@client .ssh]# ssh-copy-id root@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
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.

# 此时就是免密登陆
[root@client .ssh]# ssh root@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 failed login: Mon Oct 27 19:24:41 CST 2025 from 172.25.254.200 on ssh:notty
There were 8 failed login attempts since the last successful login.
Last login: Mon Oct 27 19:12:21 2025 from 172.25.254.200

三、Xshell 免密登陆

1.使用xshell生成密钥对 (在标题栏->工具->找到新建用户密钥引导)
2.一路下一步生成密钥,但是在公钥生成页将公钥复制
3.使用密码登录登录到远程服务器,在要登录的用户的家目录中.ssh/authorized_keys文件中写入刚刚的复制的公钥
4.重启一下服务端的sshd
5.客户端尝试远程免密登陆

http://www.dtcms.com/a/613911.html

相关文章:

  • 网站开发基础知识公众号里链接的网站怎么做的
  • 人工智能之数据分析 numpy:第四章 数组属性和数据类型
  • 网站建设所需美工app界面设计的软件
  • 营口网站建设开发制作家装公司加盟哪个公司好
  • openwrt源码编译环境搭建-安装Luci
  • synchronized全解析:从锁升级到性能优化,彻底掌握Java内置锁
  • FPGA工程师12实战项目-基于PCIe的高速ADC采集项目
  • Linux驱动开发实战指南-中
  • 网站的开发环境是什么个人制作个网站
  • 减速机在不同工况下如何安装才更稳?
  • 哪个网站可以做线上翻译赚钱织梦系统seo网站模板
  • RocketMq面试
  • 如何在建设银行网站预约纪念币黄石有哪些做视觉网站的公司
  • 手机购物网站模板如何做好专业类网站
  • 帮企业建网站wordpress google open sans
  • AI 基础与应用开发专栏搬家说明
  • GeoSeg 框架解析
  • 预训练语言模型(Pre-trained Language Model, PLM)介绍
  • 免费域名注册网站怎么登录网站运营一个月多少钱
  • 抚顺市营商环境建设局网站公众号后台登录
  • Vue2 学习记录--路由
  • Spring Boot 热部署
  • 非易失性存储器·W25Q64使用手册解读
  • 网站统计关键词重庆市建设局网站
  • 分布式缓存技术选型指南
  • mysql主从复制配置
  • html网站模板建站手机建网站推广
  • Vue 项目实战《尚医通》,预约挂号的路由与静态搭建,笔记36
  • 网站建设 风险防控网站首页的head标签内
  • 多用户跨学科交流系统(3):评论模块与 Spring Boot 全局异常处理