CentOS8 OpenSSH 升级至OpenSSH-8.5p1

CentOS8 OpenSSH 升级至OpenSSH-8.5p1

1、升级前准备

1.1、openssh升级包

官网站点下载最新版本升级包:OpenSSH-8.5p1

在这里插入图片描述

1.2、 系统版本镜像下载

本次升级的为CentOS 8.0.1905版本,此镜像已准备好并上传至系统中。

如果没有此镜像,请下载。下载链接

huaweicloud

2、升级前操作

2.1、 YUM配置

挂载镜像

[root@host-192-168-10-10 ~]# mount -t iso9660 /home/centos.iso /media    #挂载镜像
[root@host-192-168-10-10 ~]# mount -o loop /home/centos.iso /media		#挂载镜像

修改配置文件

[root@host-192-168-10-10 ~]# cd /etc/yum.repos.d/
[root@host-192-168-10-10 yum.repos.d]# ls
CentOS-AppStream.repo  CentOS-centosplus.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-PowerTools.repo  CentOS-Vault.repo
CentOS-Base.repo       CentOS-CR.repo          CentOS-Extras.repo     CentOS-Media.repo      CentOS-Sources.repo
[root@host-192-168-10-10 yum.repos.d]# mkdir bak
[root@host-192-168-10-10 yum.repos.d]# mv CentOS-* bak
[root@host-192-168-10-10 yum.repos.d]# vi system.repo
# 8.0之后安装包分在两个目录下,需要按照如下来写
[BaseOS]
name=system
baseurl=file:///media/BaseOS #镜像挂载路径,按照配置填写
enabled=1
gpgcheck=0  #0表示不用检查:

[AppStream]
name=system
baseurl=file:///media/AppStream #镜像挂载路径,按照配置填写
enabled=1
gpgcheck=0  #0表示不用检查:

[root@host-192-168-10-10 yum.repos.d]# cd /media/
[root@host-192-168-10-10 media]# ls
AppStream  BaseOS  EFI  images  isolinux  media.repo  TRANS.TBL
[root@host-192-168-10-10 media]# yum clean all
0 files removed
[root@host-192-168-10-10 media]# yum makecache 
system                                                                                                                                                        67 MB/s | 5.2 MB     00:00    
system                                                                                                                                                        78 MB/s | 2.2 MB     00:00    
Metadata cache created.
[root@host-192-168-10-10 media]#

2.2、 安装telnet

[root@host-192-168-10-10 system]# yum install -y telnet-server
Last metadata expiration check: 0:15:16 ago on Wed 17 Mar 2021 10:50:09 AM CST.
Dependencies resolved.
=============================================================================================================================================================================================
 Package                                         Arch                                     Version                                          Repository                                   Size
=============================================================================================================================================================================================
Installing:
 telnet-server                                   x86_64                                   1:0.17-73.el8                                    AppStream                                    48 k

Transaction Summary
=============================================================================================================================================================================================
Install  1 Package

Total size: 48 k
Installed size: 60 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                       1/1 
  Installing       : telnet-server-1:0.17-73.el8.x86_64    1/1 
  Running scriptlet: telnet-server-1:0.17-73.el8.x86_64    1/1 
  Verifying        : telnet-server-1:0.17-73.el8.x86_64    1/1 

Installed:
  telnet-server-1:0.17-73.el8.x86_64                          
Complete!
[root@host-10-209-30-81 system]# yum install -y xinetd
Last metadata expiration check: 0:13:50 ago on Wed 17 Mar 2021 10:50:09 AM CST.
Dependencies resolved.
=============================================================================================================================================================================================
 Package                                   Arch                                      Version                                              Repository                                    Size
=============================================================================================================================================================================================
Installing:
 xinetd                                    x86_64                                    2:2.3.15-23.el8                                      AppStream                                    135 k

Transaction Summary
=============================================================================================================================================================================================
Install  1 Package

Total size: 135 k
Installed size: 284 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                        1/1 
  Installing       : xinetd-2:2.3.15-23.el8.x86_64          1/1 
  Running scriptlet: xinetd-2:2.3.15-23.el8.x86_64          1/1 
  Verifying        : xinetd-2:2.3.15-23.el8.x86_64          1/1 

Installed:
  xinetd-2:2.3.15-23.el8.x86_64                            
Complete!
[root@host-192-168-10-10 system]# systemctl enable xinetd
[root@host-192-168-10-10 system]# systemctl enable telnet.socket
Created symlink /etc/systemd/system/sockets.target.wants/telnet.socket → /usr/lib/systemd/system/telnet.socket.
[root@host-192-168-10-10 system]# systemctl start telnet.socket
[root@host-192-168-10-10 system]# systemctl start xinetd

默认情况下,系统是不允许root用户telnet远程登录的。如果要使用root用户直接登录,需设置如下内容:

echo ‘pts/0’ >>/etc/securetty

echo ‘pts/1’ >>/etc/securetty

2.2.1、telnet登陆测试

使用telnet登陆成功后,在系统在查询,得出如下输出

[root@host-192-168-10-10 ~]# who 
root     pts/0        2021-03-17 11:10 (::ffff:172.25.246.218)
root     pts/1        2021-03-17 11:10 (172.25.246.218)

2.3、 依赖包安装

[root@host-192-168-10-10 xinetd.d]# yum install -y gcc
Last metadata expiration check: 0:19:07 ago on Wed 17 Mar 2021 10:50:09 AM CST.
Package gcc-8.2.1-3.5.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@host-192-168-10-10 xinetd.d]# yum install openssl openssl-devel -y
Last metadata expiration check: 0:19:22 ago on Wed 17 Mar 2021 10:50:09 AM CST.
Package openssl-1:1.1.1-8.el8.x86_64 is already installed.
Dependencies resolved.
=============================================================================================================================================================================================
 Package                                              Arch                                    Version                                          Repository                               Size
=============================================================================================================================================================================================
Installing:
 openssl-devel                                        x86_64                                  1:1.1.1-8.el8                                    BaseOS                                  2.3 M
Installing dependencies:
 keyutils-libs-devel                                  x86_64                                  1.5.10-6.el8                                     BaseOS                                   48 k
 krb5-devel                                           x86_64                                  1.16.1-22.el8                                    BaseOS                                  546 k
 libcom_err-devel                                     x86_64                                  1.44.3-2.el8                                     BaseOS                                   37 k
 libkadm5                                             x86_64                                  1.16.1-22.el8                                    BaseOS                                  184 k
 libselinux-devel                                     x86_64                                  2.8-6.el8                                        BaseOS                                  199 k
 libsepol-devel                                       x86_64                                  2.8-2.el8                                        BaseOS                                   85 k
 libverto-devel                                       x86_64                                  0.3.0-5.el8                                      BaseOS                                   18 k
 pcre2-devel                                          x86_64                                  10.32-1.el8                                      BaseOS                                  605 k
 pcre2-utf16                                          x86_64                                  10.32-1.el8                                      BaseOS                                  228 k
 pcre2-utf32                                          x86_64                                  10.32-1.el8                                      BaseOS                                  220 k
 zlib-devel                                           x86_64                                  1.2.11-10.el8                                    BaseOS                                   56 k

Transaction Summary
=============================================================================================================================================================================================
Install  12 Packages

Total size: 4.4 M
Installed size: 8.1 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                     1/1 
  Installing       : zlib-devel-1.2.11-10.el8.x86_64                                                                                                                                    1/12 
  Installing       : pcre2-utf32-10.32-1.el8.x86_64                                                                                                                                     2/12 
  Installing       : pcre2-utf16-10.32-1.el8.x86_64                                                                                                                                     3/12 
  Installing       : pcre2-devel-10.32-1.el8.x86_64                                                                                                                                     4/12 
  Installing       : libverto-devel-0.3.0-5.el8.x86_64                                                                                                                                  5/12 
  Installing       : libsepol-devel-2.8-2.el8.x86_64                                                                                                                                    6/12 
  Installing       : libselinux-devel-2.8-6.el8.x86_64                                                                                                                                  7/12 
  Installing       : libkadm5-1.16.1-22.el8.x86_64                                                                                                                                      8/12 
  Installing       : libcom_err-devel-1.44.3-2.el8.x86_64                                                                                                                               9/12 
  Installing       : keyutils-libs-devel-1.5.10-6.el8.x86_64                                                                                                                           10/12 
  Installing       : krb5-devel-1.16.1-22.el8.x86_64                                                                                                                                   11/12 
  Installing       : openssl-devel-1:1.1.1-8.el8.x86_64                                                                                                                                12/12 
  Running scriptlet: openssl-devel-1:1.1.1-8.el8.x86_64                                                                                                                                12/12 
  Verifying        : keyutils-libs-devel-1.5.10-6.el8.x86_64                                                                                                                            1/12 
  Verifying        : krb5-devel-1.16.1-22.el8.x86_64                                                                                                                                    2/12 
  Verifying        : libcom_err-devel-1.44.3-2.el8.x86_64                                                                                                                               3/12 
  Verifying        : libkadm5-1.16.1-22.el8.x86_64                                                                                                                                      4/12 
  Verifying        : libselinux-devel-2.8-6.el8.x86_64                                                                                                                                  5/12 
  Verifying        : libsepol-devel-2.8-2.el8.x86_64                                                                                                                                    6/12 
  Verifying        : libverto-devel-0.3.0-5.el8.x86_64                                                                                                                                  7/12 
  Verifying        : openssl-devel-1:1.1.1-8.el8.x86_64                                                                                                                                 8/12 
  Verifying        : pcre2-devel-10.32-1.el8.x86_64                                                                                                                                     9/12 
  Verifying        : pcre2-utf16-10.32-1.el8.x86_64                                                                                                                                    10/12 
  Verifying        : pcre2-utf32-10.32-1.el8.x86_64                                                                                                                                    11/12 
  Verifying        : zlib-devel-1.2.11-10.el8.x86_64                                                                                                                                   12/12 

Installed:
  openssl-devel-1:1.1.1-8.el8.x86_64   keyutils-libs-devel-1.5.10-6.el8.x86_64   krb5-devel-1.16.1-22.el8.x86_64     libcom_err-devel-1.44.3-2.el8.x86_64   libkadm5-1.16.1-22.el8.x86_64   
  libselinux-devel-2.8-6.el8.x86_64    libsepol-devel-2.8-2.el8.x86_64           libverto-devel-0.3.0-5.el8.x86_64   pcre2-devel-10.32-1.el8.x86_64         pcre2-utf16-10.32-1.el8.x86_64  
  pcre2-utf32-10.32-1.el8.x86_64       zlib-devel-1.2.11-10.el8.x86_64          

Complete!
[root@host-192-168-10-10 xinetd.d]#  echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config   #防止报错:Permission denied (publickey,keyboard-interactive)
[root@host-192-168-10-10 xinetd.d]# 

3、开始升级openssh

3.1、 上传已下载的升级包

[root@host-192-168-10-10 user01]# ls
openssh-8.5p1.tar.gz  vmtools  vmtools-3.0.0.002.tar.bz2
[root@host-192-168-10-10 user01]

3.2、 卸载旧版本openssh

[root@host-192-168-10-10 ~]#  rpm -qa|grep openssh
openssh-7.8p1-4.el8.x86_64
openssh-server-7.8p1-4.el8.x86_64
openssh-clients-7.8p1-4.el8.x86_64
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# rpm -e --nodeps openssh-7.8p1-4.el8.x86_64
[root@host-192-168-10-10 ~]# rpm -e --nodeps openssh-server-7.8p1-4.el8.x86_64
warning: /etc/ssh/sshd_config saved as /etc/ssh/sshd_config.rpmsave
[root@host-192-168-10-10 ~]# rpm -e --nodeps openssh-clients-7.8p1-4.el8.x86_64
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# 
[root@host-192-168-10-10 ~]# rpm -qa | grep openssh 
[root@host-192-168-10-10 ~]#

3.3、 解压openssh并安装

[root@host-192-168-10-10 user01]# 
[root@host-192-168-10-10 user01]# tar -zxvf openssh-8.5p1.tar.gz 
openssh-8.5p1
openssh-8.5p1/.depend
openssh-8.5p1/.github
openssh-8.5p1/.github/configs
openssh-8.5p1/.github/configure.sh
... ... ...
... ... ...
... ... ...
openssh-8.5p1/sshd_config.0
openssh-8.5p1/ssh_config.0
openssh-8.5p1/aclocal.m4
openssh-8.5p1/configure
openssh-8.5p1/config.h.in
[root@host-192-168-10-10 user01]#
[root@host-192-168-10-10 openssh-8.5p1]# install  -v -m700 -d /var/lib/sshd &&
> chown    -v root:sys /var/lib/sshd &&
> groupadd -g 50 sshd        &&
> useradd  -c 'sshd PrivSep' \
> -d /var/lib/sshd  \
> -g sshd           \
> -s /bin/false     \
> -u 50 sshd
install: creating directory '/var/lib/sshd'
changed ownership of '/var/lib/sshd' from root:root to root:sys
groupadd: group 'sshd' already exists
[root@host-192-168-10-10 openssh-8.5p1]# ./configure --prefix=/usr                     \
> --sysconfdir=/etc/ssh             \
> --with-md5-passwords              \
> --with-privsep-path=/var/lib/sshd &&
> make
configure: loading site script /usr/share/config.site
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
... ... ...
... ... ...
... ... ...
[root@host-192-168-10-10 openssh-8.5p1]# make install
(cd openbsd-compat && make)
make[1]: Entering directory '/home/user01/openssh-8.5p1/openbsd-compat'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/user01/openssh-8.5p1/openbsd-compat'
/usr/bin/mkdir -p /usr/bin
/usr/bin/mkdir -p /usr/sbin
/usr/bin/mkdir -p /usr/share/man/man1
/usr/bin/mkdir -p /usr/share/man/man5
/usr/bin/mkdir -p /usr/share/man/man8
... ... ...
... ... ...
... ... ...
/usr/sbin/sshd -t -f /etc/ssh/sshd_config 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
sshd: no hostkeys available -- exiting.
make: [Makefile:374: check-config] Error 1 (ignored)
[root@host-192-168-10-10 openssh-8.5p1]# chmod 600 /etc/ssh/ssh_host_rsa_key
[root@host-192-168-10-10 openssh-8.5p1]# chmod 600 /etc/ssh/ssh_host_ecdsa_key
[root@host-192-168-10-10 openssh-8.5p1]# chmod 600 /etc/ssh/ssh_host_ed25519_key
[root@host-192-168-10-10 openssh-8.5p1]# 
[root@host-192-168-10-10 openssh-8.5p1]# make install 
(cd openbsd-compat && make)
make[1]: Entering directory '/home/user01/openssh-8.5p1/openbsd-compat'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/user01/openssh-8.5p1/openbsd-compat'
/usr/bin/mkdir -p /usr/bin
/usr/bin/mkdir -p /usr/sbin
/usr/bin/mkdir -p /usr/share/man/man1
... ... ...
... ... ...
... ... ...
/usr/bin/install -c -m 644 sftp.1.out /usr/share/man/man1/sftp.1
/usr/bin/install -c -m 644 sftp-server.8.out /usr/share/man/man8/sftp-server.8
/usr/bin/install -c -m 644 ssh-keysign.8.out /usr/share/man/man8/ssh-keysign.8
/usr/bin/install -c -m 644 ssh-pkcs11-helper.8.out /usr/share/man/man8/ssh-pkcs11-helper.8
/usr/bin/install -c -m 644 ssh-sk-helper.8.out /usr/share/man/man8/ssh-sk-helper.8
/usr/bin/mkdir -p /etc/ssh
/etc/ssh/ssh_config already exists, install will not overwrite
/etc/ssh/sshd_config already exists, install will not overwrite
/etc/ssh/moduli already exists, install will not overwrite
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
[root@host-192-168-10-10 openssh-8.5p1]# ssh -V   #检查版本号
OpenSSH_8.5p1, OpenSSL 1.1.1 FIPS  11 Sep 2018
[root@host-192-168-10-10 openssh-8.5p1]# install -v -m755    contrib/ssh-copy-id /usr/bin     &&
> install -v -m644    contrib/ssh-copy-id.1 \
> /usr/share/man/man1              &&
> install -v -m755 -d /usr/share/doc/openssh-8.5p1     &&
> install -v -m644    INSTALL LICENCE OVERVIEW README* \
> /usr/share/doc/openssh-8.5p1
'contrib/ssh-copy-id' -> '/usr/bin/ssh-copy-id'
'contrib/ssh-copy-id.1' -> '/usr/share/man/man1/ssh-copy-id.1'
install: creating directory '/usr/share/doc/openssh-8.5p1'
'INSTALL' -> '/usr/share/doc/openssh-8.5p1/INSTALL'
'LICENCE' -> '/usr/share/doc/openssh-8.5p1/LICENCE'
'OVERVIEW' -> '/usr/share/doc/openssh-8.5p1/OVERVIEW'
'README' -> '/usr/share/doc/openssh-8.5p1/README'
'README.dns' -> '/usr/share/doc/openssh-8.5p1/README.dns'
'README.md' -> '/usr/share/doc/openssh-8.5p1/README.md'
'README.platform' -> '/usr/share/doc/openssh-8.5p1/README.platform'
'README.privsep' -> '/usr/share/doc/openssh-8.5p1/README.privsep'
'README.tun' -> '/usr/share/doc/openssh-8.5p1/README.tun'
[root@host-192-168-10-10 openssh-8.5p1]# 

3.4、 root用户访问

[root@host-192-168-10-10 ssh]# echo "PermitRootLogin no" >> /etc/ssh/sshd_config
[root@host-192-168-10-10 ssh]# echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
[root@host-192-168-10-10 ssh]# echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
[root@host-192-168-10-10 ssh]#

4、 系统服务处理

[root@host-192-168-10-10 ssh]# cd /home/user01/openssh-8.5p1/
[root@host-192-168-10-10 openssh-8.5p1]# cp -p contrib/redhat/sshd.init /etc/init.d/sshd 
[root@host-192-168-10-10 openssh-8.5p1]# chmod +x /etc/init.d/sshd 
[root@host-192-168-10-10 openssh-8.5p1]# chkconfig  --add  sshd 
[root@host-192-168-10-10 openssh-8.5p1]# chkconfig  sshd  on 
[root@host-192-168-10-10 openssh-8.5p1]# chkconfig  --list  sshd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@host-192-168-10-10 openssh-8.5p1]# 
[root@host-192-168-10-10 openssh-8.5p1]# systemctl restart sshd
[root@host-192-168-10-10 openssh-8.5p1]# systemctl status sshd
● sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd; generated)
   Active: active (running) since Wed 2021-03-17 11:28:26 CST; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 16347 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
 Main PID: 16357 (sshd)
    Tasks: 1 (limit: 11512)
   Memory: 1.2M
   CGroup: /system.slice/sshd.service
           └─16357 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups

Mar 17 11:28:26 host-192-168-10-10 systemd[1]: Starting SYSV: OpenSSH server daemon...
Mar 17 11:28:26 host-192-168-10-10 sshd[16357]: Server listening on 0.0.0.0 port 22.
Mar 17 11:28:26 host-192-168-10-10 sshd[16357]: Server listening on :: port 22.
Mar 17 11:28:26 host-192-168-10-10 sshd[16347]: [27B blob data]
Mar 17 11:28:26 host-192-168-10-10 systemd[1]: Started SYSV: OpenSSH server daemon.
[root@host-192-168-10-10 openssh-8.5p1]# 
[root@host-192-168-10-10 openssh-8.5p1]# ssh -V
OpenSSH_8.5p1, OpenSSL 1.1.1 FIPS  11 Sep 2018
[root@host-192-168-10-10 openssh-8.5p1]# vi /etc/selinux/config
......
......
#SELINUX=enforcing
SELINUX=disabled 
......
......
[root@host-192-168-10-10 openssh-8.5p1]#
[root@host-192-168-10-10 openssh-8.5p1]# reboot 

Connection closed by foreign host.

5、 参考资料

OpenSSH-8.5p1: http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值