yum管理&openssh-

yum工具的使用和ssh

rpm的缺点

在使用rpm安装软件时,如果遇到有依赖关系的软件时就需要先安装依赖软件才能安装需要安装的软件,一个两个还无所谓,一旦依赖关系多了rpm安装软件就显得费时又费心,而yum工具可以自行解决依赖关系使得安装软件不在费时费力。

yum工作原理

1:配置仓库:在Yum的配置文件中,我们定义了一个或多个仓库的URL或本地路径。这些配置文件通常位于/etc/yum.repos.d/目录中。每个仓库定义都包含名称、URL/路径、GPG密钥验证等信息。

2:执行操作:当用户向Yum发送安装、更新或删除软件包等命令时,Yum会根据配置文件中的仓库信息,从对应的仓库中获取软件包信息。

3:解析依赖:Yum会解析软件包的依赖关系,并确保所需的依赖包也会被下载和安装。这样可以方便地管理软件包的依赖关系,使得安装或更新软件包时不会遗漏必要的依赖。

4:下载软件包:一旦确定需要下载哪些软件包,Yum会通过HTTP或FTP等协议连接到指定的仓库地址,并开始下载软件包及其相关文件。Yum可以使用多个并行连接来加速下载过程。

4:安装软件包:下载完成后,Yum会自动安装软件包并将其配置到系统中。如果有必要,它还会运行相应的脚本来执行配置或启用服务等操作。

yum的配置文件

vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever   //缓存目录
keepcache=0     //缓存软件包, 1启动 0 关闭
debuglevel=2    //调试级别
logfile=/var/log/yum.log    //日志记录位置
exactarch=1     //检查平台是否兼容
obsoletes=1     //检查包是否废弃
gpgcheck=1      //检查来源是否合法,需要有制作者的公钥信息
plugins=1       //是否启用插件
tolerant={1|0}  //容错功能,1为开启,0为关闭,当设为0时,如果用yum安装多个软件包且其中某个软件包已经安装过就会报错;当设为1时,当要安装的软件已经安装时自动忽略
installonly_limit=5
bugtracker_url
# metadata_expire=90m //每小时手动检查元数据
# in /etc/yum.repos.d   //包含repos.d目录 

本地源:

使用本地源首先需要将光盘映像文件挂载到系统,然后编写配置文件yum源就可正常使用了

例:

###:挂载系统映像文件
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
###:编写域名配置文件如下
[root@localhost ~]# cat /etc/yum.repos.d/1.repo 
[baseos]
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

[appstream]
baseurl=file:///mnt/AppStream 
enabled=1
gpgcheck=0
[root@localhost ~]# 
####:参数详解
 仓库名称[]:具有唯一性,不应与其他软件仓库发生冲突
       描述信息(name):介绍性的词,易于辨认该仓库的作用
       仓库位置(baseurl):仓库的具体路径,接受以下三种类型
    ftp://
    http://
    file:///
       是否启用(enabled):.设置此源是否可用,是为1,禁用为0
       是否校验(gpgcheck):设置此源是否校验源文件,是为1,禁用为0
     公钥的位置(gpgkey):如果上面gpgcheck参数开启了校验功能,则此处为公匙文件位置。如未开启则不需要标识

网络源:

网络源于本地源的区别在于,不需要挂载光盘映像文件,缺点就是网络源依赖网络,在一些内网环境中就没有本地源灵活,但是由于本地源的繁琐条件,导致每台主机都需挂载映像文件,所以一般在大型服务器环境中将yum源搭建为一台单独的服务器,通过内网地址与各个主机建立连接,实现yum源可用,而配置也可进一步精简,将baseurl=file:///mnt/BaseOS换成网络地址就可完成网络源的安装

[root@localhost ~]# cat /etc/yum.repos.d/2.repo 
[baseos]
name=BaseOS
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/
enabled=1
gpgcheck=0

[appstream]
name=AppStream
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-stream/9-stream/AppStream/x86_64/os/ 
enabled=1
gpgcheck=0
[root@localhost ~]# 

yum常用命令

参数作用
-y安装过程自动回答yes
-q静默模式,安装时不输出信息
命令作用
clean all清理yum仓库本地缓存
list all ()检验yum本地仓库
–installed列出已经安装的包
–updates可用的升级
repoliat显示repo列表及其简要信息
install <软件名>安装软件
update升级软件
remove/erase卸载软件
history查看yum历史安装信息
localinstall安装本地rpm包,后接本地包完整路径
grouplist列出可用的组
groupinstall“组名”安装一组软件
createrepo创建yum仓库的源数据信息
info列出软件包的详情

例:

####:列出已经安装的包(vim)
[root@localhost ~]# yum list installed |grep vim 
Repository 'baseos' is missing name in configuration, using id.
Repository 'appstream' is missing name in configuration, using id.
vim-common.x86_64                           2:8.2.2637-20.el9_1       @appstream
vim-enhanced.x86_64                         2:8.2.2637-20.el9_1       @appstream
vim-filesystem.noarch                       2:8.2.2637-20.el9_1       @baseos   
vim-minimal.x86_64                          2:8.2.2637-20.el9_1       @anaconda 
[root@localhost ~]# 
###:列出可以安装的vsftp包
[root@localhost ~]# yum list all |grep vsftp
Repository 'baseos' is missing name in configuration, using id.
Repository 'appstream' is missing name in configuration, using id.
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
vsftpd.x86_64                               3.0.5-4.el9               @System   
[root@localhost ~]# 
####:列出软件包的详情
[root@localhost ~]# yum info vsftpd
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Repository 'baseos' is missing name in configuration, using id.
Repository 'appstream' is missing name in configuration, using id.
Repository baseos is listed more than once in the configuration
Repository appstream is listed more than once in the configuration
Installed Packages
Name         : vsftpd
Version      : 3.0.5
Release      : 4.el9
Architecture : x86_64
Size         : 347 k
Source       : vsftpd-3.0.5-4.el9.src.rpm
Repository   : @System
Summary      : Very Secure Ftp Daemon
URL          : https://security.appspot.com/vsftpd.html
License      : GPLv2 with exceptions
Description  : vsftpd is a Very Secure FTP daemon. It was written completely from
             : scratch.

[root@localhost ~]# 

当不小心将每个服务的配置文件误删了,就可以将提供这个配置文件的服务进行重装,使得配置文件得以重置

[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vsftpd.conf.rpmsave
[root@localhost vsftpd]# rm -f vsftpd.conf
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd_conf_migrate.sh  vsftpd.conf.rpmsave
[root@localhost vsftpd]# 
[root@localhost yum.repos.d]# yum -y reinstall vsftpd
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:00:36 ago on Tue 04 Jul 2023 04:23:23 PM CST.
Dependencies resolved.
-----------------省略-----------------
[root@localhost yum.repos.d]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vsftpd.conf.rpmsave

更新软件包

命令作用
check-update对比已经安装的软件,有哪些升级
update更新软件

与仓库相关的命令

命令作用
yum repolist列出yum源可用的软件仓库yum源不可用不会列出
yum repolist all列出所有yum源可用和禁用的仓库
yum provides <命令或者文件绝对路径>查看某个命令或者文件属于那个包

与缓存相关的命令

命令作用
yum makecache缓存yum源软件仓库(安装软件时会自动缓存)
yum clean all清理yum源软件仓库

与包组相关的命令

列出可用的包组

yum groups list

[root@localhost vsftpd]# yum groups list 
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:20:17 ago on Tue 04 Jul 2023 04:30:38 PM CST.
Available Environment Groups:
   Server with GUI
   Server
   Workstation
   Custom Operating System
   Virtualization Host
Installed Environment Groups:
   Minimal Install
Available Groups:
   Legacy UNIX Compatibility
   Console Internet Tools
   Container Management
   Development Tools
   .NET Development
   Graphical Administration Tools
   Headless Management
   Network Servers
   RPM Development Tools
   Scientific Support
   Security Tools
   Smart Card Support
   System Tools
[root@localhost vsftpd]# 

安装包组

yum groups install <包组名>

[root@localhost vsftpd]# yum groups  install server

Updating Subscription Management repositories.
Unable to read consumer identity
-----省略----
Transaction Summary
===============================================================================================
Install  208 Packages

Total download size: 137 M
Installed size: 406 M

与历史记录相关

查看历史执行yum命令

[root@localhost vsftpd]# yum history
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

ID     | Command line                             | Date and time    | Action(s)      | Altered
-----------------------------------------------------------------------------------------------
    14 | update                                   | 2023-07-04 16:28 | I, U           |  161 EE
    13 | -y reinstall vsftpd                      | 2023-07-04 16:24 | R              |    2  <
    12 | -y install wget                          | 2023-07-03 14:08 | Install        |    1 > 
    11 | -y install bind-utils                    | 2023-07-03 09:33 | Install        |    7   
    10 | install -y bash-completion               | 2023-06-30 16:18 | Install        |    5   
     9 | -y install NetworkManager-initscripts-up | 2023-06-30 16:04 | Install        |    1   
     8 | install -y net-tools                     | 2023-06-30 14:36 | Install        |    1   
     7 | -y install zip                           | 2023-06-28 16:27 | Install        |    2   
     6 | -y install bzip2                         | 2023-06-28 16:08 | Install        |    1   
     5 | remove -y iptraf                         | 2023-06-28 09:56 | Removed        |    1   
     4 | install -y iptraf                        | 2023-06-28 09:54 | Install        |    1   
     3 | -y install tree                          | 2023-06-28 09:50 | Install        |    1   
     2 | -y install vim                           | 2023-06-28 09:50 | Install        |    4   
     1 |                                          | 2023-06-27 09:44 | Install        |  383 EE
[root@localhost vsftpd]# 

查看历史执行yum命令id的详细信息

[root@localhost vsftpd]# yum history info 3
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Transaction ID : 3
Begin time     : Wed 28 Jun 2023 09:50:34 AM CST
Begin rpmdb    : 355002b4c222df5f3db11ac46eb409a819a19d31854051c1ee2d922f33b6e04a
End time       : Wed 28 Jun 2023 09:50:34 AM CST (0 seconds)
End rpmdb      : 9022943c410a6d9cf40aaac356baf24a1b50373c1f72924bbc804c26a935e72d
User           : root <root>
Return-Code    : Success
Releasever     : 9
Command Line   : -y install tree
Comment        : 
Packages Altered:
    Install tree-1.8.0-10.el9.x86_64 @baseos
[root@localhost vsftpd]# 

撤销历史执行过的yum命令 和卸载命令类似

[root@localhost vsftpd]# yum history undo 3
------省略----------
 tree              x86_64              1.8.0-10.el9                 @baseos              113 k

Transaction Summary
===============================================================================================
Remove  1 Package

Freed space: 113 k
Is this ok [y/N]: y
-----------省略--------------------

Removed:
  tree-1.8.0-10.el9.x86_64                                                                     

Complete!
[root@localhost vsftpd]# 

yum签名检查机制

yum签名机制工作原理

  1. 软件仓库维护者使用私钥对软件包进行签名。私钥通常由软件仓库提供者保密保管。
  2. 在使用YUM进行软件包操作之前,YUM首先从软件仓库获取包含软件包信息和签名的元数据文件。
  3. YUM使用公钥来验证元数据文件的签名是否有效。公钥是保存在本地系统上的,它是由软件仓库提供者分发的。
  4. 如果签名有效,YUM会继续进行软件包操作。否则,YUM会警告签名验证失败,并停止操作。

在软件仓库配置文件中开启认证:

[baseos]
name=BaseOS
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
enabled=1
gpgcheck=1  #:开启公钥验证
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official  ####:公钥位置

[appstream]
name=AppStream
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/ 
enabled=1
gpgcheck=1  #:同上
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official


openssh

OpenSSH是一个开源的用于安全远程登录和文件传输的软件套件。它提供了加密的通信通道,可以在不安全的网络中安全地传输数据。

OpenSSH主要包括以下几个组件:

  1. sshd(SSH守护进程):用于服务器端,接受远程登录请求并提供安全的Shell会话。

  2. ssh(SSH客户端):用于客户端,通过SSH协议与远程服务器建立安全连接,提供远程登录和文件传输功能。

  3. scp(Secure Copy):用于在本地主机和远程主机之间安全地复制文件。

  4. sftp(SSH File Transfer Protocol):提供了对文件的安全传输和管理。

OpenSSH的工作原理如下:

  1. 客户端发起与服务器的连接请求。

  2. 服务器验证客户端的身份和权限,对于合法的客户端连接请求,服务器启动sshd进程。

  3. 客户端与服务器之间建立起安全连接,使用非对称加密和密钥交换来确保通信的机密性。

  4. 在安全连接建立后,客户端可以使用SSH客户端进行远程登录和执行命令,或者使用scp、sftp进行文件传输。

以当前用户建立远程登陆

[root@localhost ~]# ssh 192.168.62.150
The authenticity of host '192.168.62.150 (192.168.62.150)' can't be established.
ED25519 key fingerprint is SHA256:XrGx5KVezxgl3crEZx4B10aJayoNd7j3XXJXjtBZaNA.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.62.150' (ED25519) to the list of known hosts.
root@192.168.62.150's password: 
Last login: Tue Jul  4 17:55:26 2023 from 192.168.62.1

以当前用户建立连接仅限于对方主机拥有本地主机这个用户,如果对方主机没有这个用户则登录失败

C:\Users\liuhongsheng>ssh 192.168.62.150
The authenticity of host '192.168.62.150 (192.168.62.150)' can't be established.
ED25519 key fingerprint is SHA256:XrGx5KVezxgl3crEZx4B10aJayoNd7j3XXJXjtBZaNA.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.62.150' (ED25519) to the list of known hosts.
liuhongsheng@192.168.62.150's password:
Permission denied, please try again.
liuhongsheng@192.168.62.150's password:
Permission denied, please try again.
liuhongsheng@192.168.62.150's password:


指定用户登录目标主机

C:\Users\liuhongsheng>ssh root@192.168.62.128
The authenticity of host '192.168.62.128 (192.168.62.128)' can't be established.
ED25519 key fingerprint is SHA256:mAStX3eKA2y5zMXqRui6b252rWHd7SrpQLMiROX524s.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.62.128' (ED25519) to the list of known hosts.
root@192.168.62.128's password:
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: Tue Jul  4 08:26:08 2023 from 192.168.62.1


使用远程用户身份在远程主机上通过将输出返回到本地显示器的方式执行一条单一命令

###:本地主机
[root@localhost ~]# ssh root@192.168.62.150 'touch /root/xixi'
root@192.168.62.150's password: 
[root@localhost ~]# 
#目标主机
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  xixi  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# 


ssh主机密钥

SSH主机密钥是用于在SSH连接中进行身份验证和数据加密的一对密钥,包括公钥和私钥。每个SSH服务器都有一个唯一的主机密钥对。

SSH主机密钥由服务器生成,并保存在服务器的特定位置。当客户端第一次连接到SSH服务器时,服务器会向客户端发送它的公钥。客户端会将该公钥保存在本地的"known_hosts"文件中。

接下来的每次连接,客户端都会检查服务器发送的公钥是否与之前保存的公钥匹配。如果匹配成功,客户端可以安全地与服务器建立连接。如果不匹配,客户端会发出警告,提示可能存在风险并拒绝链接。

SSH主机密钥具有以下两种类型:

  1. 主机公钥(Host Public Key):服务器向客户端发送的公钥,用于加密会话和验证服务器的身份。

  2. 主机私钥(Host Private Key):服务器私有地保存的密钥,用于解密从客户端发送的数据。

主机公钥和主机私钥的组合形成了SSH主机密钥对,确保了连接的安全性和身份验证。

主机密钥信息存储在本地客户机系统上的:/root/.ssh目录的known——hosts中

主机密钥贼服务器上存储的位置是:/etc/ssh/ ssh_host_ecdsa_key.pub中(不同主机密钥文件名有所区别 但是一定是ssh_host_*key为名)

密钥文件:

客户端:
[root@localhost .ssh]# cat known_hosts
192.168.62.150 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKlw92SRe1ILOJI56SYn0MX3qvInyj3KVvSTgCW2zmhh
192.168.62.150 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOFpzNhyOidq3Od/0UbBnZ8d2AnaUzMdZBn8ArrMIoZXMaW5RNuvWp8V3FjFFvr0gzPvaknLjECV8fuTqeFLRd8=
主机端
[root@localhost ssh]# cat ssh_host_ecdsa_key.pub 
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOFpzNhyOidq3Od/0UbBnZ8d2AnaUzMdZBn8ArrMIoZXMaW5RNuvWp8V3FjFFvr0gzPvaknLjECV8fuTqeFLRd8= 
[root@localhost ssh]# 

配置基于 SSH 密钥的身份验证

参数作用
-b设置密钥长度
-q静默模式
-t设置要创建的密钥类型
-C设置注释信息

生成SSH密钥对:在本地计算机上生成SSH密钥对,包括公钥和私钥。

##:中间会询问一些东西一直回车就可以了
[root@localhost .ssh]# ssh-keygen -t rsa -C "这是密钥"
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:j55odNiS0qE+9IOJMC4174MXRKdXUonU4tFSxkhxgc0 这是密钥
The key's randomart image is:
+---[RSA 3072]----+
|     o+&*o       |
|    . XoE        |
|   . + *         |
|    o +          |
|   . + =S        |
|o o = * oo       |
|.+ B B o. .      |
|..o O +o .       |
|.  o.+..o        |
+----[SHA256]-----+
[root@localhost .ssh]# 
[root@localhost .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC693LgHJjl/BvK9NCtRr8bCcJQyhD+7+WKzRZbiqox0V9qDxSS2VCrXa1yNDQ/TRR3N0Ryy5PLbKcevz94CKMPosYk45YueTeYSKMxKzJzvdDrYDS8/hQjqA0IO/uVy4B1WnfKfeRUdp5odP7CyMp/yIzp0a2nhYuHiRjDb/N5DENKClnJp+ieCninEK/L7j0t1JPbhVLCUxaWWwt7137Ou2lPuKVsK3N8wCSSrOQm3Wu/FFr5OPcp4zP/DoJTvMQbqv4FVdZxAPva4c3AHke32LdFKjfPPRXhK2R2pLIOz4h3QBm9RuylLyQ6y1/kTFtYg1bxJIhHWBwQjGuoaokkhBFRbiuTjc0ZA9m23GnSbrGR5Rdq3wTBygC3vbQgOKUrFhls6A7B9rfHqzDblgfbCn2VBvyzCTuClMFzjzVf9pBWY8xEywON7NIPQPOAw0IJG3nQS8ZxV9pjhGZr3eEJWbMxgq7CZXVzCpqx+KdVSsTqrxqr1B5AGN3w/vTXfV8= 这是密钥
[root@localhost .ssh]# 

将公钥添加到服务器上:将生成的公钥添加到要进行SSH密钥身份验证的目标服务器上。:

[root@localhost .ssh]# ssh-copy-id  root@192.168.62.150
/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.62.150's password: 

Number of key(s) added: 1

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

[root@localhost .ssh]# 

该命令会将公钥复制到服务器的~/.ssh/authorized_keys文件中。

[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls
authorized_keys
[root@localhost .ssh]# cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC693LgHJjl/BvK9NCtRr8bCcJQyhD+7+WKzRZbiqox0V9qDxSS2VCrXa1yNDQ/TRR3N0Ryy5PLbKcevz94CKMPosYk45YueTeYSKMxKzJzvdDrYDS8/hQjqA0IO/uVy4B1WnfKfeRUdp5odP7CyMp/yIzp0a2nhYuHiRjDb/N5DENKClnJp+ieCninEK/L7j0t1JPbhVLCUxaWWwt7137Ou2lPuKVsK3N8wCSSrOQm3Wu/FFr5OPcp4zP/DoJTvMQbqv4FVdZxAPva4c3AHke32LdFKjfPPRXhK2R2pLIOz4h3QBm9RuylLyQ6y1/kTFtYg1bxJIhHWBwQjGuoaokkhBFRbiuTjc0ZA9m23GnSbrGR5Rdq3wTBygC3vbQgOKUrFhls6A7B9rfHqzDblgfbCn2VBvyzCTuClMFzjzVf9pBWY8xEywON7NIPQPOAw0IJG3nQS8ZxV9pjhGZr3eEJWbMxgq7CZXVzCpqx+KdVSsTqrxqr1B5AGN3w/vTXfV8= 这是密钥
[root@localhost .ssh]# 

如果无法使用ssh-copy-id命令,也可以手动将公钥内容复制到服务器的~/.ssh/authorized_keys文件中。

现在本地用户登录目标主机就可以实现免密登录了

[root@localhost .ssh]# ssh root@192.168.62.150
Last login: Tue Jul  4 17:55:54 2023 from 192.168.62.128
[root@localhost ~]# 

虽然OpenSSH服务器通常无需修改,但会提供其他安全措施,可以在配置文件/etc/ssh/sshd_config中修改OpenSSH服务器的各个方面。

PermitRootLogin {yes|no}    //是否允许root用户远程登录系统
PermitRootLogin without-password    //仅允许root用户基于密钥方式远程登录
PasswordAuthentication {yes|no}     //是否启用密码身份验证,默认开启

ssh安全注意事项

密码经常更换并且足够复杂

1:tr命令的使用

[root@localhost .ssh]#  tr -dc A-Za-z0-9_ < /dev/urandom | head -c 70 |xargs ## 随机生成70位密码
sPLWNFy0uTLs1gwaN3FbiZAAxLvx3TTAv9pkUJ3D0mlDgOlzZQQfdfSfGM_ganHt6SVSyK
[root@localhost .ssh]# 
###随机生成20位密码
[root@localhost .ssh]# openssl rand  -base64 20
Al6Ct4PL/7p1/uWNRA/VYNy/cQI=
[root@localhost .ssh]# 


2:使用非默认端口

3:限制登录客户端地址

4:仅监听特定的IP地址

5:禁止管理员直接登录

6:仅允许有限制用户登录

7:使用基于密钥的认证

8:禁止使用空密码

9:禁止使用SSHv1版本

10:设定空闲会话超时时长

11:利用防火墙设置ssh访问策略

12:限制ssh的访问频度和并发在线数

13:做好日志的备份,经常分析(集中于某台服务器)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值