yum管理openssh服务

news2024/12/30 3:29:10

文章目录

  • yum工具使用
      • 1.yum的配置文件
      • 2.yum仓库的管理
        • 本地仓库
        • 网络仓库
      • 3.使用yum管理软件
          • list
          • clean
          • repolist
          • install
          • update
          • downgrade
          • remove
          • info
          • provides
          • history
          • deplist
          • grouplist
          • groupinstall
  • openssh
      • sshd服务
      • Secure Shell 示例
      • ssh主机密钥
      • 配置免密登录
      • SSH 安全注意事项

yum工具使用

1.yum的配置文件

yum的repo配置文件的路径

[root@LC ~]# cd /etc/yum.repos.d/
[root@LC yum.repos.d]# pwd
/etc/yum.repos.d
[root@LC yum.repos.d]# 

#yum的repo文件要以.repo结尾,要不然系统不会读取
[root@LC yum.repos.d]# ls
lcc.repo  lc.repo  redhat.repo
[root@LC yum.repos.d]# 

yum的主配置文件

/etc/yum.conf
[root@LC ~]# cat /etc/yum.conf 
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
[root@LC ~]# 

主配置文件的各种各样的参数

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的repo配置文件的内容

(这是搭建好的本地仓库)

[root@LC yum.repos.d]# cat lc.repo 
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
[root@LC yum.repos.d]# 

在这里插入图片描述

[Repo_Name]:仓库名称
name:描述信息(可以自定义)
baseurl:仓库的具体路径,接受以下三种类型
    ftp://
    http://
    file:///

enabled:可选值{1|0},1为启用此仓库,0为禁用此仓库
gpgcheck:可选值{1|0},1为检查软件包来源合法性,0为不检查来源
    如果gpgcheck设为1,则必须用gpgkey定义密钥文件的具体路径
    gpgkey=/PATH/TO/KEY

2.yum仓库的管理

根据你的需求去定义一个repo文件,你可以使用本地镜像的资源,也可以使用网络镜像的资源

官方网络yum仓库(国外)
阿里云yum仓库
163yum仓库
xx大学yum仓库
epel源
本地仓库

搭建一个本地仓库:

1.先确定本地的iso光盘是否连接

在这里插入图片描述

或者在右下角找到这个小圆圈右键

在这里插入图片描述

在这里插入图片描述

右键它可以选择连接,已连接就不用管了

2.挂载光盘

临时挂载

[root@LC ~]# mount /dev/sr0 /mnt/
mount: /mnt: WARNING: source write-protected, mounted read-only.


[root@LC ~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
devtmpfs              devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs                 tmpfs     972M     0  972M   0% /dev/shm
tmpfs                 tmpfs     389M   11M  379M   3% /run
/dev/mapper/rhel-root xfs        17G  1.4G   16G   9% /
/dev/sda1             xfs      1014M  236M  779M  24% /boot
tmpfs                 tmpfs     195M     0  195M   0% /run/user/0
/dev/sr0              iso9660   9.0G  9.0G     0 100% /mnt    //显示出挂载信息
[root@LC ~]# 

永久挂载

[root@LC ~]# mount /dev/sr0 /mnt/
mount: /mnt: /dev/sr0 already mounted on /mnt.
[root@LC ~]# vim /etc/fstab 
[root@LC ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jun 26 09:53:32 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=b1821db2-a464-452f-b583-aef06d6d8b38 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   none                    swap    defaults        0 0
/dev/sr0 /mnt iso9660 defaults 0 0               //手动添加此行内容
[root@LC ~]# 

3.进入repo配置文件目录,编写一个.repo结尾的文件

[root@LC ~]# cd /etc/yum.repos.d/
[root@LC yum.repos.d]# vim lc.repo
[root@LC yum.repos.d]# cat lc.repo 
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
[root@LC yum.repos.d]# 

4.清除缓存

[root@LC ~]# yum clean all
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 listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
13 files removed
[root@LC ~]# 

5.检查本地仓库文件

[root@LC yum.repos.d]# yum list all
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.

BaseOS                                          228 MB/s | 1.7 MB     00:00    
AppStream                                       341 MB/s | 6.3 MB     00:00    
Installed Packages
NetworkManager.x86_64                         1:1.42.2-1.el9          @anaconda 
NetworkManager-initscripts-updown.noarch      1:1.42.2-3.el9_2        @BaseOS   
NetworkManager-libnm.x86_64                   1:1.42.2-1.el9          @anaconda 
NetworkManager-team.x86_64                    1:1.42.2-1.el9          @anaconda 
NetworkManager-tui.x86_64                     1:1.42.2-1.el9          @anaconda 
acl.x86_64                                    2.3.1-3.el9             @anaconda 
alternatives.x86_64                           1.20-2.el9              @anaconda 
audit.x86_64                                  3.0.7-103.el9           @anaconda 
audit-libs.x86_64                             3.0.7-103.el9           @anaconda 
            (省略)
网络仓库

搭建网络仓库很简单,就是repo配置文件里面的baseurl后面的链接换成网络镜像站里面的连接

当然你要自己根据需求去找到对应的包的连接

注意:本地仓库和网络仓库不能同时开启

清华大学开源镜像站

在这里插入图片描述


阿里云镜像站

在这里插入图片描述

配置网络仓库

1.根据需求找到对应的链接,复制下来

在这里插入图片描述

2.编写一个repo配置文件

baseurl后面就写找到的链接

[root@LC yum.repos.d]# vim lcc.repo 
[root@LC yum.repos.d]# cat lcc.repo 
[BaseOS]
name=BaseOS
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
 
[AppStream]
name=AppStream
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0
enabled=1
[root@LC yum.repos.d]# 

3.清除缓存

[root@LC ~]# yum clean all 
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.

13 files removed
[root@LC ~]# 

4.查看仓库文件

[root@LC ~]# yum list all
(省略)

3.使用yum管理软件

语法:yum [options] [command] [package ...]
--nogpgcheck                //如果从网上下载包有时会检查gpgkey,此时可以使用此命令跳过gpgkey的检查
-y                          //自动回答为"yes"
-q                          //静默模式,安装时不输出信息至标准输出
--disablerepo=repoidglob    //临时禁用此处指定的repo
--enablerepo=repoidglob     //临时启用此处指定的repo
--noplugins                 //禁用所有插件

常用的参数

list            //列表
    all         //默认项
    available   //列出仓库中有的,但尚未安装的所有可用的包
    installed   //列出已经安装的包
    updates     //可用的升级
    
clean           //清理缓存
    packages
    headers
    metadata
    dbcache
    all
    
repolist        //显示repo列表及其简要信息
    all
    enabled     //默认项
    disabled
    
install         //安装
    yum install packages [...]
    
update          //升级
    yum update packages [...]
update_to       //升级为指定版本

downgrade package1 [package2 ...]   //降级

remove|erase    //卸载

info    //显示rpm -qi package的结果
    yum info packages
    
provides|whatprovides   //查看指定的文件或特性是由哪个包安装生成的

search string1 [string2 ...]    //以指定的关键字搜索程序包名及summary信息

deplist package [package2 ...]  //显示指定包的依赖关系

history     //查看yum的历史事务信息

localinstall    //安装本地rpm包,自动解决依赖关系

grouplist       //列出可用的组

groupinstall "group name"   //安装一组软件
        
createrepo命令    //创建yum仓库的元数据信息
list
list            //列表
    all         //默认项
    available   //列出仓库中有的,但尚未安装的所有可用的包
    installed   //列出已经安装的包
    updates     //可用的升级

例子:

[root@LC ~]# yum list all
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.

BaseOS                                          741 kB/s | 6.2 MB     00:08    
AppStream                                       1.1 MB/s |  17 MB     00:16    
Last metadata expiration check: 0:00:01 ago on Tue 04 Jul 2023 10:53:02 AM CST.
Installed Packages
NetworkManager.x86_64                       1:1.42.2-1.el9            @anaconda 
NetworkManager-initscripts-updown.noarch    1:1.42.2-3.el9_2          @BaseOS   
NetworkManager-libnm.x86_64                 1:1.42.2-1.el9            @anaconda 
NetworkManager-team.x86_64                  1:1.42.2-1.el9            @anaconda 
NetworkManager-tui.x86_64                   1:1.42.2-1.el9            @anaconda 
acl.x86_64                                  2.3.1-3.el9               @anaconda 
alternatives.x86_64                         1.20-2.el9                @anaconda 
(省略)
clean
clean           //清理缓存
    packages
    headers
    metadata
    dbcache
    all

例子:

清理所有缓存:yum clean all

[root@LC ~]# yum clean all
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.

13 files removed

清理包:yum clean packages

[root@LC ~]# yum clean packages 
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.

0 files removed

(省略)

repolist
repolist        //显示repo列表及其简要信息
    all
    enabled     //默认项
    disabled

例子:

[root@LC ~]# yum repolist 
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.

repo id                                 repo name
AppStream                               AppStream
BaseOS                                  BaseOS
[root@LC ~]# 

[root@LC ~]# yum repolist all

在这里插入图片描述

看最后一列字符可以知道库是否启用

  • enabled代表启动
  • disabled代表未启动

查看正在启用的库

[root@LC yum.repos.d]# yum repolist enabled 
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.

repo id                                 repo name
AppStream                               AppStream
[root@LC yum.repos.d]# 

查看未启用的库

[root@LC yum.repos.d]# yum repolist disabled 
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.

repo id                                  repo name
BaseOS                                   BaseOS
[root@LC yum.repos.d]# 

install

//安装

yum install packages [...]
-y  确定安装
-q  静默安装   (不显示过程)
[root@LC ~]# yum -y install vim
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.

BaseOS                                           14 kB/s | 3.9 kB     00:00    
AppStream                                        11 kB/s | 4.4 kB     00:00    
Dependencies resolved.
================================================================================
 Package             Arch        Version                   Repository      Size
================================================================================
Installing:
 vim-enhanced        x86_64      2:8.2.2637-20.el9         AppStream      1.8 M
Installing dependencies:
 gpm-libs            x86_64      1.20.7-29.el9             AppStream       21 k
 vim-common          x86_64      2:8.2.2637-20.el9         AppStream      7.0 M
 vim-filesystem      noarch      2:8.2.2637-20.el9         BaseOS          18 k

Transaction Summary
================================================================================
Install  4 Packages

Total download size: 8.8 M
Installed size: 34 M
Downloading Packages:
(1/4): vim-filesystem-8.2.2637-20.el9.noarch.rp  40 kB/s |  18 kB     00:00    
(2/4): gpm-libs-1.20.7-29.el9.x86_64.rpm         45 kB/s |  21 kB     00:00    
(3/4): vim-enhanced-8.2.2637-20.el9.x86_64.rpm  1.8 MB/s | 1.8 MB     00:00    
(4/4): vim-common-8.2.2637-20.el9.x86_64.rpm    2.7 MB/s | 7.0 MB     00:02    
--------------------------------------------------------------------------------
Total                                           3.3 MB/s | 8.8 MB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : gpm-libs-1.20.7-29.el9.x86_64                          1/4 
  Installing       : vim-filesystem-2:8.2.2637-20.el9.noarch                2/4 
  Installing       : vim-common-2:8.2.2637-20.el9.x86_64                    3/4 
  Installing       : vim-enhanced-2:8.2.2637-20.el9.x86_64                  4/4 
  Running scriptlet: vim-enhanced-2:8.2.2637-20.el9.x86_64                  4/4 
  Verifying        : vim-filesystem-2:8.2.2637-20.el9.noarch                1/4 
  Verifying        : gpm-libs-1.20.7-29.el9.x86_64                          2/4 
  Verifying        : vim-common-2:8.2.2637-20.el9.x86_64                    3/4 
  Verifying        : vim-enhanced-2:8.2.2637-20.el9.x86_64                  4/4 
Installed products updated.

Installed:
  gpm-libs-1.20.7-29.el9.x86_64         vim-common-2:8.2.2637-20.el9.x86_64    
  vim-enhanced-2:8.2.2637-20.el9.x86_64 vim-filesystem-2:8.2.2637-20.el9.noarch

Complete!
[root@LC ~]# 

update
update          //升级
    yum update packages [...]
update_to       //升级为指定版本

演示:

[root@LC ~]# rpm -qa | grep which
which-2.21-28.el9.x86_64             //已经安装了发行号为28的版本


[root@LC ~]# yum list updates | grep which
which.x86_64                               2.21-29.el9                 BaseOS                                //查询出有发行号为29的新版本
[root@LC ~]# 


//更新版本
[root@LC ~]# yum -y update which.x86_64 
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:12:39 ago on Tue 04 Jul 2023 11:11:30 AM CST.
Dependencies resolved.
================================================================================
 Package         Architecture     Version                Repository        Size
================================================================================
Upgrading:
 which           x86_64           2.21-29.el9            BaseOS            41 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 41 k
Downloading Packages:
which-2.21-29.el9.x86_64.rpm                     72 kB/s |  41 kB     00:00    
--------------------------------------------------------------------------------
Total                                            72 kB/s |  41 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Upgrading        : which-2.21-29.el9.x86_64                               1/2 
  Cleanup          : which-2.21-28.el9.x86_64                               2/2 
  Running scriptlet: which-2.21-28.el9.x86_64                               2/2 
  Verifying        : which-2.21-29.el9.x86_64                               1/2 
  Verifying        : which-2.21-28.el9.x86_64                               2/2 
Installed products updated.

Upgraded:
  which-2.21-29.el9.x86_64                                                      

Complete!



[root@LC ~]# rpm -qa | grep which
which-2.21-29.el9.x86_64                //已经更新为发行号为29的版本
[root@LC ~]# 

downgrade
downgrade package1 [package2 ...]   //降级
remove
//卸载
-y      确定
-q      静默(不显示过程)
[root@LC ~]# yum -y remove vim 
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.

Dependencies resolved.
================================================================================
 Package             Arch        Version                  Repository       Size
================================================================================
Removing:
 vim-enhanced        x86_64      2:8.2.2637-20.el9        @AppStream      3.8 M
Removing unused dependencies:
 gpm-libs            x86_64      1.20.7-29.el9            @AppStream       28 k
 vim-common          x86_64      2:8.2.2637-20.el9        @AppStream       30 M
 vim-filesystem      noarch      2:8.2.2637-20.el9        @BaseOS          40  

Transaction Summary
================================================================================
Remove  4 Packages

Freed space: 34 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Erasing          : vim-enhanced-2:8.2.2637-20.el9.x86_64                  1/4 
  Erasing          : vim-common-2:8.2.2637-20.el9.x86_64                    2/4 
  Erasing          : vim-filesystem-2:8.2.2637-20.el9.noarch                3/4 
  Erasing          : gpm-libs-1.20.7-29.el9.x86_64                          4/4 
  Running scriptlet: gpm-libs-1.20.7-29.el9.x86_64                          4/4 
  Verifying        : gpm-libs-1.20.7-29.el9.x86_64                          1/4 
  Verifying        : vim-common-2:8.2.2637-20.el9.x86_64                    2/4 
  Verifying        : vim-enhanced-2:8.2.2637-20.el9.x86_64                  3/4 
  Verifying        : vim-filesystem-2:8.2.2637-20.el9.noarch                4/4 
Installed products updated.

Removed:
  gpm-libs-1.20.7-29.el9.x86_64         vim-common-2:8.2.2637-20.el9.x86_64    
  vim-enhanced-2:8.2.2637-20.el9.x86_64 vim-filesystem-2:8.2.2637-20.el9.noarch

Complete!
info

和rpm -qi显示的内容一样

[root@LC ~]# yum info which.x86_64 
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:24:35 ago on Tue 04 Jul 2023 11:11:30 AM CST.
Installed Packages
Name         : which
Version      : 2.21
Release      : 29.el9
Architecture : x86_64
Size         : 80 k
Source       : which-2.21-29.el9.src.rpm
Repository   : @System
From repo    : BaseOS
Summary      : Displays where a particular program in your path is located
URL          : https://savannah.gnu.org/projects/which/
License      : GPLv3
Description  : The which command shows the full pathname of a specified program,
             : if the specified program is in your PATH.

[root@LC ~]# 
provides
//查看指定的文件或特性是由哪个包安装生成的
[root@LC ~]# yum provides /usr/bin/ls
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:55:28 ago on Tue 04 Jul 2023 11:11:30 AM CST.
coreutils-8.32-31.el9.x86_64 : A set of basic GNU tools commonly used in shell
                             : scripts
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/ls

coreutils-8.32-32.el9.x86_64 : A set of basic GNU tools commonly used in shell
                             : scripts
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/ls
(省略)




[root@LC ~]# yum provides /etc/passwd
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:56:23 ago on Tue 04 Jul 2023 11:11:30 AM CST.
setup-2.13.7-6.el9.noarch : A set of system configuration and setup files
Repo        : BaseOS
Matched from:
Filename    : /etc/passwd

setup-2.13.7-7.el9.noarch : A set of system configuration and setup files
Repo        : BaseOS
Matched from:
Filename    : /etc/passwd

setup-2.13.7-8.el9.noarch : A set of system configuration and setup files
Repo        : BaseOS
Matched from:
Filename    : /etc/passwd

setup-2.13.7-9.el9.noarch : A set of system configuration and setup files
Repo        : @System
Matched from:
Filename    : /etc/passwd

setup-2.13.7-9.el9.noarch : A set of system configuration and setup files
Repo        : BaseOS
Matched from:
Filename    : /etc/passwd

[root@LC ~]# 

history

//查看yum的历史事务信息

[root@LC ~]# 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
-------------------------------------------------------------------------------
    26 | -y install vim           | 2023-07-04 11:34 | Install        |    4   
    25 | -y remove vim            | 2023-07-04 11:34 | Removed        |    4   
    24 | -y update which.x86_64   | 2023-07-04 11:24 | Upgrade        |    1   
    23 | -y -q remove wget.x86_64 | 2023-07-04 11:15 | Removed        |    1   
    22 | -y install vim           | 2023-07-04 11:11 | Install        |    4   
    21 | -y remove vim            | 2023-07-04 11:10 | Removed        |    4   
    20 | update -y kmod-kvdo      | 2023-07-04 09:35 | I, U           |    4   
    19 | -y install wget          | 2023-07-03 14:05 | Install        |    1   
    18 | -y install bind-utils.x8 | 2023-07-03 09:00 | Install        |    7   
    17 | -y install NetworkManage | 2023-06-30 16:00 | Install        |    1   
    16 | -y install net-tools     | 2023-06-30 15:49 | Install        |    1   
    15 | -y install bash-completi | 2023-06-30 14:41 | Install        |    5   
    14 | -y install biosdevname   | 2023-06-30 14:11 | Install        |    1   
    13 | -y remove biosdevname    | 2023-06-30 14:11 | Removed        |    1   
    12 | -y install biosdevname   | 2023-06-30 14:10 | Install        |    1   
    11 | remove nano              | 2023-06-30 08:51 | Removed        |    1   
    10 | -y install nano          | 2023-06-30 08:50 | Install        |    1   
     9 | -y install bzip2         | 2023-06-28 14:22 | Install        |    1   
     8 | -y install vdo kmod-kvdo | 2023-06-27 15:11 | Install        |    2   
     7 | -y install tree          | 2023-06-27 15:02 | Install        |    1   
     6 | remove tree              | 2023-06-27 15:01 | Removed        |    1   
     5 | -y install vim           | 2023-06-27 15:00 | Install        |    4   
     4 | remove vim               | 2023-06-27 15:00 | Removed        |    4   
     3 | -y install tree          | 2023-06-27 14:18 | Install        |    1   
     2 | -y install vim           | 2023-06-27 10:01 | Install        |    4   
     1 |                          | 2023-06-26 17:53 | Install        |  383 EE
[root@LC ~]# 
deplist

//显示指定包的依赖关系

[root@LC ~]# yum deplist which
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: 1:00:06 ago on Tue 04 Jul 2023 11:11:30 AM CST.
package: which-2.21-27.el9.x86_64
  dependency: libc.so.6(GLIBC_2.34)(64bit)
   provider: glibc-2.34-68.el9.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.34-68.el9.i686
   provider: glibc-2.34-68.el9.x86_64

package: which-2.21-28.el9.x86_64
  dependency: libc.so.6(GLIBC_2.34)(64bit)
   provider: glibc-2.34-68.el9.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.34-68.el9.i686
   provider: glibc-2.34-68.el9.x86_64

package: which-2.21-29.el9.x86_64
  dependency: libc.so.6(GLIBC_2.34)(64bit)
   provider: glibc-2.34-68.el9.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.34-68.el9.i686
   provider: glibc-2.34-68.el9.x86_64
[root@LC ~]# 

grouplist

//列出可用的组

[root@LC ~]# yum grouplist 
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: 1:01:35 ago on Tue 04 Jul 2023 11:11:30 AM 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@LC ~]# 

groupinstall

安装一组软件

[root@LC ~]# yum -y groupinstall "resolvedep"
(省略)

openssh

常见的远程登录工具有:

telnet
ssh
dropbear
telnet      //远程登录协议,23/TCP
    认证明文
    数据传输明文

ssh         //Secure SHell,应用层协议,22/TCP
    通信过程及认证过程是加密的,主机认证
    用户认证过程加密
    数据传输过程加密
    
dropbear    //嵌入式系统专用的SSH服务器端和客户端工具

sshd服务

服务器端    //sshd,配置文件在/etc/ssh/sshd_config
客户端     //ssh,配置文件在/etc/ssh/ssh_config
    ssh-keygen      //密钥生成器
    ssh-copy-id     //将公钥传输至远程服务器
    scp             //跨主机安全复制工具

服务状态

[root@LC ~]# systemctl status sshd

在这里插入图片描述

默认是开启的,如果没有开启,就不能进行ssh远程连接


服务的配置文件

1.服务端的配置文件

[root@LC ~]# cat /etc/ssh/sshd_config
#	$OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# To modify the system-wide sshd configuration, create a  *.conf  file under
#  /etc/ssh/sshd_config.d/  which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
(省略)

2.客户端的配置文件

[root@LC ~]# cat /etc/ssh/ssh_config
#	$OpenBSD: ssh_config,v 1.35 2020/07/17 03:43:42 dtucker Exp $

# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
(省略)

Secure Shell 示例

//以当前用户身份创建远程交互式shell,然后在结束时使用exit命令返回到之前的shell

[root@LC ~]# ssh 192.168.179.133        //这里没有指定用户,就默认是以对面主机的root用户
root@192.168.179.133'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 16:26:32 2023 from 192.168.179.1
[root@lc9-2 ~]# 

在第一次远程联机对面主机时,对面主机会发送一个公钥过来,这个文件会存到本地主机的.ssh下的叫konw.hosts的文件,里面的内容就是公钥主机认证)

[root@LC ~]# cd .ssh/
[root@LC .ssh]# ls
known_hosts  known_hosts.old
[root@LC .ssh]# 
[root@LC .ssh]# cat known_hosts.old 
192.168.179.133 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPydM5QDi58bRc7KwZnjOdFNfU0S+dZNhSvRD3prWFgF
[root@LC .ssh]# 

//以其他用户身份(remoteuser)在选定主机(remotehost)上连接到远程shell

[root@LC ~]# ssh lc2@192.168.179.133            //这里的lc2是对面主机上的普通用户
lc2@192.168.179.133'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 16:33:19 2023
[lc2@lc9-2 ~]$ 

//以远程用户身份(remoteuser)在远程主机(remotehost)上通过将输出返回到本地显示器的方式来执行单一命令

示例一:这里执行的ip a 是在对面主机上执行的,但是结果显示在本机上
[root@LC ~]# ssh root@192.168.179.133 'ip a'
root@192.168.179.133's password: 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:a6:c7:16 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.179.133/24 brd 192.168.179.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea6:c716/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@LC ~]# 


示例二:用本机连接对面的主机,在/tmp下创建一个名为666的文件
[root@LC ~]# ssh root@192.168.179.133 'touch /tmp/666'
root@192.168.179.133's password: 
[root@LC ~]# 

[root@lc9-2 ~]# ls /tmp/
666             //666在这里已经创建好了
systemd-private-e90a7a38564048a89373d0a0f7253af1-chronyd.service-Z6oJ41
systemd-private-e90a7a38564048a89373d0a0f7253af1-dbus-broker.service-XZy8SA
systemd-private-e90a7a38564048a89373d0a0f7253af1-systemd-logind.service-HlMuNo
vmware-root_843-4021784525
[root@lc9-2 ~]# 

ssh主机密钥

当用户第一次使用ssh连接到特定服务器时,`ssh`命令可在用户的~/.ssh/known_hosts文件中存储该服务器的公钥。在此之后每当用户进行连接时,客户端都会通过对比~/.ssh/known_hosts文件中的服务器条目和服务器发送的公钥,确保从服务器获得相同的公钥。如果公钥不匹配,客户端会假定网络通信已遭劫持或服务器已被入侵,并且中断连接。

这意味着,如果服务器的公钥发生更改(由于硬盘出现故障导致公钥丢失,或者出于某些正当理由替换公钥),用户则需要更新其~/.ssh/known_hosts文件并删除旧的条目才能够进行登录。

存储在本地客户端公钥文件

[root@LC ~]# cd .ssh/
[root@LC .ssh]# ls
known_hosts  known_hosts.old
[root@LC .ssh]# cat known_hosts.old 
192.168.179.133 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPydM5QDi58bRc7KwZnjOdFNfU0S+dZNhSvRD3prWFgF
[root@LC .ssh]# 

存储在服务端的公钥文件

.pub是公钥 (ssh_host_ecdsa_key )

没有.pub是私钥 (ssh_host_ecdsa_key.pub)

[root@LC ~]# cd /etc/ssh
[root@LC ssh]# ls
moduli        sshd_config.d           ssh_host_ed25519_key.pub
ssh_config    ssh_host_ecdsa_key      ssh_host_rsa_key
ssh_config.d  ssh_host_ecdsa_key.pub  ssh_host_rsa_key.pub
sshd_config   ssh_host_ed25519_key
[root@LC ssh]# 

配置免密登录

尝试远程连接

[root@LC ~]# ssh root@192.168.179.133
root@192.168.179.133's password: 
(发现需要密码,ctrl+c终止连接)

生成密钥

[root@LC ~]# ls .ssh/
known_hosts  known_hosts.old
[root@LC ~]# 

[root@LC ~]# 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:69OZTOWszssu0nSt99wBuoDgOw+Bn7BAx8U/yuMCoXU root@LC
The key's randomart image is:
+---[RSA 3072]----+
|    ..           |
|  . ..           |
| . o  .          |
|..o E  o    .    |
|.o.+.o. S  = .   |
|... =++ o.o = .  |
|  ...=.+.* *   . |
|   . o+.+oO o. ..|
|    ..oo.=*+ .o .|
+----[SHA256]-----+
[root@LC ~]# 

[root@LC ~]# ls .ssh/
id_rsa  id_rsa.pub  known_hosts  known_hosts.old    //此时多了两个文件
[root@LC ~]# 

id_rsa.pub是公钥
id_rsa 是私钥

//将公钥传输给远程主机上

[root@LC ~]# ssh-copy-id root@192.168.179.133
/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.179.133's password: 

Number of key(s) added: 1

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

[root@LC ~]# 


去对面主机查看
[root@lc9-2 ~]# ls .ssh/
authorized_keys  known_hosts  known_hosts.old     //authorized_keys就是
[root@lc9-2 ~]# 

//使用ssh无密码登录远程主机

[root@LC ~]# ssh root@192.168.179.133
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 17:11:06 2023 from 192.168.179.123
[root@lc9-2 ~]# 
//直接登录进来了

scp命令远程下载

在远程主机上创建一个文件
[root@lc9-2 ~]# touch /opt/999
[root@lc9-2 ~]# ls /opt/
999
[root@lc9-2 ~]# 


在本机上使用scp命令下载文件999到本地
[root@LC ~]# scp root@192.168.179.133:/opt/999 /root
[root@LC ~]# 
[root@LC ~]# ls /root/
anaconda-ks.cfg 	999

scp命令远程传输

在本机创建一个文件888
[root@LC ~]# touch /opt/888
[root@LC ~]# ls /opt/
888  
[root@LC ~]# 



在本机上使用scp命令把文件888传输到远程主机
[root@LC ~]# scp /opt/888 root@192.168.179.133:/opt/
888                                          100%    0     0.0KB/s   00:00    
[root@LC ~]# 



在远程主机上查看
[root@lc9-2 ~]# ls /opt/
888  999
[root@lc9-2 ~]# 

SSH 安全注意事项

生成密码

tr -dc A-Za-z0-9_ < /dev/urandom | head -c 30 |xargs   //生成30位的密码
[root@LC ~]# tr -dc A-Za-z0-9_ < /dev/urandom | head -c 30 |xargs
0gskmwWT3kWF_K_h4JfVqIycaHAdQS
[root@LC ~]# 


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

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

相关文章

【文件操作】Java -操作File对象

个人简介&#xff1a;Java领域新星创作者&#xff1b;阿里云技术博主、星级博主、专家博主&#xff1b;正在Java学习的路上摸爬滚打&#xff0c;记录学习的过程~ 个人主页&#xff1a;.29.的博客 学习社区&#xff1a;进去逛一逛~ 文件操作 Java - File对象 Java - File对象 Fi…

Matlab绘制散点的95%置信区间图

Matlab常绘制95%置信区间图&#xff0c;主要使用到patch函数。 如果直接使用散点进行拟合&#xff0c;在patch函数绘制95%置信区间时&#xff0c;会绘制的很乱&#xff0c;这个是由于patch函数所导致的&#xff0c;其实这个问题在 Matlab绘制95%置信区间图 中已经讲到过&#…

JS 严格模式和正常模式详解

JavaScript 严格模式&#xff08;Strict Mode&#xff09;和正常模式&#xff08;Non-Strict Mode&#xff09;是用于控制 JavaScript 代码执行的两种不同模式。严格模式引入了一些限制和变化&#xff0c;旨在帮助开发人员编写更可靠、安全和高效的代码。在本文中&#xff0c;我…

js实现将文本生成二维码(腾讯云cos)

示例 页面代码 import { getQCodeUrl } from /utils/cosInstance; import { PageContainer } from ant-design/pro-components; import { Access, useAccess } from umijs/max; import { Button, Image } from antd; import { useState } from react;const AccessPage: Reac…

SpringCloud复习:(2)@LoadBalanced注解的工作原理

LoadBalanced注解标记了一个RestTemplate或WebClient bean使用LoadBalancerClient来进行负载均衡。 LoadBalancerAutoConfiguration类给带注解的RestTemplate添加了拦截器&#xff1a;LoadBalancerInterceptor. 具体流程如下&#xff1a; 首先定义一个LoadBalancerInterceptor…

超强满血不收费的AI绘图教程来了(在线Stable Diffusion一键即用)

超强满血不收费的AI绘图教程来了&#xff08;在线Stable Diffusion一键即用&#xff09; 一、简介1.1 AI绘图1.2 Stable Diffusion1.2.1 原理简述1.2.2 应用流程 二、AI绘图工具2.1 吐司TusiArt2.2 哩布哩布LibLibAI2.3 原生部署 三、一键即用3.1 开箱尝鲜3.2 模型关联3.3 Cont…

小白必看,手把手教你重装系统

一&#xff0c;安装步骤 二&#xff0c;重装之前需要做的准备 1、重装之前请大家务必注意备份重要资料。电脑有价&#xff0c;数据无价——重要数据备份之后&#xff0c;电脑随便折腾都没问题。大不了就是重装不成功。系统软件问题多试几次总能解决的&#xff0c;但重要数据一…

《红蓝攻防对抗实战》七.常规反弹之利用NC在Linux系统执行反弹shell

目录 一.利用NC工具在linux执行反弹shell 1.Linux正向连接shell 2.利用Linux自带bash反弹Shell 前文推荐&#xff1a; 《红蓝攻防对抗实战》一. 隧道穿透技术详解《红蓝攻防对抗实战》二.内网探测协议出网之TCP/UDP协议探测出网《红蓝攻防对抗实战》三.内网探测协议出网之H…

最新壁纸自动采集系统网站PHP源码/360壁纸官方数据接口采集/ZHEYI采集源码

源码介绍&#xff1a; 最新壁纸自动采集系统网站PHP源码&#xff0c;它是ZHEYI自动采集源码&#xff0c;能够在360壁纸官方数据接口采集。很好用的壁纸网站源码分享&#xff0c;仅供学习&#xff0c;请勿商用。 ZHEYI自动采集壁纸PHP源码&#xff0c;能全自动采集高清壁纸网源…

设计模式—设计模式总览

设计模式—设计模式总览 在 1994 年&#xff0c;由 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides 四人合著出版了一本名为 《Design Patterns - Elements of Reusable Object-Oriented Software》&#xff08;中文译名&#xff1a;《设计模式 - 可复用的面向对…

Wish如何入驻?最全防封攻略

近日来&#xff0c;跨境电商平台Wish有了新改革&#xff0c;为提高产品质量把控效率&#xff0c;Wish最近将入驻机制又完全开放转变为“邀请制”&#xff0c;加强了品控措施&#xff0c;也意味着商家入驻门槛变高&#xff0c;流程与之前截然不同。但对于已有跨境电商经验/没有跨…

Mybatis 简介(一)

这里使用的是3.5.11版本 MyBatis 是一款优秀的持久层框架&#xff0c;它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO&#xff08;P…

非连续分配管理方式-基本分页存储管理

非连续分配-可为用户进程分配分散的内存空间 一、存储过程 1.将内存空间分成大小相等的分区&#xff0c;每个分区为一个页框/页帧(内存块/物理块/物理页面)&#xff0c;每个页框有一个编号(页框号/内存块号/物理块号)&#xff0c;从0开始 2.将进程的逻辑地址空间也分为与页框…

在NodeJS中使用npm包实现JS代码混淆加密

使用npm包&#xff0c;在NodeJS中实现JS代码混淆加密 在前后端JS开发过程中&#xff0c;JS代码保护&#xff08;JS代码混淆加密&#xff09;是非常重要的一环。 JShaman是一个云端的代码保护Saas平台&#xff0c;可以对JS代码进行混淆、加密、压缩等操作&#xff0c;从而增强…

[极客大挑战 2019]EasySQL

【解题思路】 1.打开靶机链接 2.输入数据进行尝试 输入1,1&#xff1a; 可以在导航栏里面看到username和password的变量。 3.使用万能密码 username&#xff1a;1 or 11# username&#xff1a;任意数据 password&#xff1a;任意数据 …

传统制造业如何转型?什么是智能工厂?

本文将为大家讲解&#xff1a;传统制造业如何转型&#xff1f;什么是智能工厂&#xff1f; 一、传统工业存在哪些痛点 相较于新兴工业&#xff0c;传统工业在当前发展放缓&#xff0c;并受到了一波互联网数字化智能化发展的冲击。 1、低效率和高成本 传统工业通常采用传统的…

C算法:写一个用于找出数组的最大值和最小值的函数

需求&#xff1a; 写一个用于找出数组的最大值和最小值的函数。 示例&#xff1a;int array[9] {5, 9, 3, 1, 2, 8, 4, 7, 6}; 该数组最大值的下标为1&#xff0c;最小值的小标为3。 代码实现&#xff1a; #include <stdio.h>int getNum(int *array,int len,int (*…

【JAVA学习笔记】39 - final关键字

项目代码 https://github.com/yinhai1114/Java_Learning_Code/tree/main/IDEA_Chapter10/src/com/yinhai/final_ 一、final关键字基本介绍 final可以修饰类、属性、方法和局部变量&#xff0c; 在某些情况下&#xff0c;程序员可能有以下需求&#xff0c;就会使用到final 1)当…

C算法:米m 转化 英尺foot和英寸inch

需求&#xff1a; 已知1英尺等于12英寸&#xff0c;如果已知英制长度的英尺foot和英寸inch的值&#xff0c;那么对应的米是(footinch/12)*0.3048&#xff0c;现在&#xff0c;用户输入的是厘米数&#xff0c;那么对应英制长度的英尺和英寸是多少呢? 输入样例&#xff1a; 1…

ITSource 分享 第4期【简洁的问卷调查系统】

项目介绍 本期给大家介绍一个 简洁的问卷的调查系统。 一 业务介绍 本系统分为以下几个模块: 1.登录注册 2.新建问卷 注册登录完成后,即可进入首页 可以创建问卷 目前只有单选&#xff0c;多选&#xff0c;简答三种问题类型&#xff0c;并且可以选择手动结束和自动结束模式。…