当前位置:   article > 正文

CentOS7.x从openssh7.4p1升级到openssh8.4p1_openssh升级后版本号没变

openssh升级后版本号没变

 

1、升级准备工作

1.1、查看系统版本和ssh版本

  1. cat /etc/redhat-release
  2. ssh -V

 1.2、需要将openssh升级到最新版本

直接yum安装即可

yum install openssh -y

 可以看已经升级到7.4p1了,下面将从openssh7.4p1升级到openssh8.4p1

 1.3、安装需要的依赖包

yum -y install gcc gcc-c++ kernel-devel

 2、安装包准备

2.1、下载安装包

 zlib-1.2.11.tar.gz 下载地址:http://www.zlib.net/zlib-1.2.11.tar.gz     也可以直接下载:wget http://www.zlib.net/zlib-1.2.11.tar.gz

openssl-1.1.1h.tar.gz 下载地址:https://www.openssl.org/source/openssl-1.1.1h.tar.gz  也可以直接下载:wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz

openssh-8.4p1.tar.gz 下载地址:http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz  也可以直接下载:wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz

查看安装包:

 2.2、解压安装包,我习惯将安装包解压到/usr/local/src下面

  1. tar xf openssh-8.4p1.tar.gz -C /usr/local/src/
  2. tar xf openssl-1.1.1h.tar.gz -C /usr/local/src/
  3. tar xf zlib-1.2.11.tar.gz -C /usr/local/src/
  4. ll /usr/local/src/

3、安装

3.1、安装zlib-1.2.11.tar.gz

  1. [root@test3 ~]# cd /usr/local/src/zlib-1.2.11/
  2. [root@test3 zlib-1.2.11]# ./configure --prefix=/usr/local/zlib && make -j 4 && make install

3.2、安装 openssl-1.1.1h.tar.gz

  1. [root@test3 zlib-1.2.11]# cd /usr/local/src/openssl-1.1.1h/
  2. [root@test3 openssl-1.1.1h]# ./config --prefix=/usr/local/ssl -d shared

[root@test3 openssl-1.1.1h]# make -j 4 && make install

[root@test3 openssl-1.1.1h]# echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
[root@test3 openssl-1.1.1h]# ldconfig -v

3.3、安装openssh-8.4p1.tar.gz

  1. mv /etc/ssh /etc/ssh.bak
  2. cd /usr/local/src/openssh-8.4p1/
  3. ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib
  4. make -j 4 && make install

sshd_config文件修改

复制代码

  1. echo "X11Forwarding yes" >> /etc/ssh/sshd_config
  2. echo "X11UseLocalhost no" >> /etc/ssh/sshd_config                
  3. echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config
  4. echo "UseDNS no" >> /etc/ssh/sshd_config
  5. echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
  6. echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
  7. echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config

复制代码

 需要添加X11Forwarding yes开启X11转发,调用图形界面,如oracle安装等操作需要图形界面

***必须添加X11UseLocalhost no 和 XAuthLocation /usr/bin/xauth 这两项,否则X11转发不好使

验证X11转发是否好使,xhost +  出现下面的是可以正常使用的

 出现下面的内容是不能正常使用的

 备份 /etc/ssh 原有文件,并将新的配置复制到指定目录

复制代码

  1. mv /usr/sbin/sshd /usr/sbin/sshd.bak
  2. cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
  3. mv /usr/bin/ssh /usr/bin/ssh.bak
  4. cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh
  5. mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
  6. cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

复制代码

查看版本ssh -V

4、启动sshd

直接systemctl start sshd,启动不起来,报错,但用sshd -t检查也没有啥错误,就提示timeout

  问题解决:先停掉sshd服务,将systemctl原服务器删除,使用安装包里自带的sshd.init,复制到/etc/init.d/sshd,重启即可

复制代码

  1. systemctl stop sshd.service
  2. rm -rf /lib/systemd/system/sshd.service
  3. systemctl daemon-reload
  4. cp /usr/local/src/openssh-8.4p1/contrib/redhat/sshd.init /etc/init.d/sshd
  5. /etc/init.d/sshd restart
  6. systemctl status sshd

复制代码

启动不起来,可以使用/etc/init.d/sshd restart重启即可

添加开机启动

chkconfig --add  sshd

chkconfig --list sshd

 5、为了防止升级失败,可以在升级之前安装telnet服务,通过Telnet连接服务器进行升级

5.1、安装telnet-server以及xinetd

yum install xinetd telnet-server -y

vim /etc/xinetd.d/telnet

复制代码

  1. service telnet
  2. {
  3. disable = yes
  4. flags = REUSE
  5. socket_type = stream
  6. wait = no
  7. user = root
  8. server = /usr/sbin/in.telnetd
  9. log_on_failure += USERID
  10. }

复制代码

配置telnet登录的终端类型,在/etc/securetty文件末尾增加一些pts终端,如下

  1. vim /etc/securetty
  2. pts/0
  3. pts/1
  4. pts/2
  5. pts/3

tail -5 /etc/securetty

  1. xvc0
  2. pts/0
  3. pts/1
  4. pts/2
  5. pts/3

systemctl enable xinetd

systemctl enable telnet.socket

systemctl start telnet.socket

systemctl start xinetd

netstat -lntp|grep 23

netstat可能会报错,原因是没有安装net-tools工具包

yum install net-tools -y

再次查看

  切换到telnet方式登录,以后的操作都在telnet终端下操作,防止ssh连接意外中断造成升级失败

 

 5.2、删除Telnet服务

  1. systemctl disable xinetd.service
  2. systemctl stop xinetd.service
  3. systemctl disable telnet.socket
  4. systemctl stop telnet.socket
  5. netstat -lntp

卸载yum remove telnet-server xinetd -y

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/249368
推荐阅读
相关标签
  

闽ICP备14008679号