zoukankan      html  css  js  c++  java
  • centos6.5升级openssh至7.9p1

    环境说明
    系统环境:centos 6.5 x64 openssh-5.3p1
    升级原因:低版本openssh存在漏洞
    升级目标:openssh-7.9p1

    检查环境
    官方文档中提到的先决条件openssh安装依赖zlib1.1.4并且openssl>=1.0.1版本就可以了。

    当前版本正好符合openssh7.9p1的安装条件,而且zlib也符合OpenSSH7.9P1的依赖,可以进行直接安装:
    [root@noway11 ~]# openssl version
    OpenSSL 1.0.1e-fips 11 Feb 2013
    [root@noway11 ~]# rpm -q zlib
    zlib-1.2.3-29.el6.x86_64
    [root@noway11 ~]# rpm -q zlib-devel
    zlib-devel-1.2.3-29.el6.x86_64

    开启telnet-server服务
    为防止openssh升级过程中断开连接,最好开启telnet-server服务以防万一
    [root@noway11 ~]yum -y install telnet-server*
    [root@noway11 ~]service iptables stop
    [root@noway11 ~]chkconfig iptables off
    [root@noway11 ~]sed -i 's/(.*)disable(.*)/ disable = no/g' /etc/xinetd.d/telnet ##将其中disable字段的yes改为no以启用telnet服务
    [root@noway11 ~]mv /etc/securetty /etc/securetty.old #允许root用户通过telnet登录
    [root@noway11 ~]service xinetd start
    [root@noway11 ~]chkconfig xinetd on

    openssh-7.9p1升级
    [root@noway11 ~]yum install -y gcc openssl-devel pam-devel rpm-build pam-devel
    [root@noway11 ~]#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz #或者从官网下载,上传至服务器
    [root@noway11 ~]rpm -e `rpm -qa | grep openssh` --nodeps
    [root@noway11 ~]cd /usr/local/src/ && tar zxvf openssh-7.9p1_Compile.tar.gz && cd openssh-7.9p1
    [root@noway11 ~]./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers && make && make install
    [root@noway11 ~]sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config #或手动修改PermitRootLogin no 修改为 PermitRootLogin yes 允许root远程登陆
    [root@noway11 ~]sed -i 's/#PermitEmptyPasswords(.*)/PermitEmptyPasswords no/g' /etc/ssh/sshd_config ##禁止空密码
    [root@noway11 ~]sed -i 's/^SELINUX(.*)/SELINUX=disabled/g' /etc/selinux/config ##重点来了~~~禁止selinux 否则重启后会登录失败
    [root@noway11 ~]echo 'KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1' >> /etc/ssh/sshd_config ## 写上新版ssh支持的算法
    [root@noway11 ~]cp contrib/redhat/sshd.init /etc/init.d/sshd
    [root@noway11 ~]chkconfig --add sshd
    [root@noway11 ~]chkconfig sshd on
    [root@noway11 ~]service sshd start
    [root@noway11 ~]service sshd restart
    [root@noway11 ~]chkconfig --list sshd
    [root@noway11 ~]ssh -V

    关闭telnet-server服务
    升级完成,通过ssh可以远程到服务器后,可以关闭telnet-server服务
    [root@noway11 ~]mv /etc/securetty.old /etc/securetty #允许root用户通过telnet登录
    [root@noway11 ~]service xinetd stop
    [root@noway11 ~]chkconfig xinetd off
    [root@noway11 ~]service iptables start
    [root@noway11 ~]chkconfig iptables on
    将之前改过的disable=yes又改回去成no.
    随后再将修改iptables将23端口关闭,并重启iptables服务.
    至此,可以再开ssh登录,用ssh -V查看版本号

    启动报错问题

    sshd启动报错:Bad SSH2 KexAlgorithms '...'

    查询支持的算法:
    [user@localhost ~]# ssh -Q kex
    diffie-hellman-group1-sha1
    diffie-hellman-group14-sha1
    diffie-hellman-group14-sha256
    diffie-hellman-group16-sha512
    diffie-hellman-group18-sha512
    diffie-hellman-group-exchange-sha1
    diffie-hellman-group-exchange-sha256
    ecdh-sha2-nistp256
    ecdh-sha2-nistp384
    ecdh-sha2-nistp521
    curve25519-sha256
    curve25519-sha256@libssh.org
    也可以用paste -s -d,直接将查询结果串接并写入配置文件:

    echo 'KexAlgorithms' `ssh -Q kex | paste -d, -s` >> /etc/ssh/sshd_config

    报错排查技巧
    遇到错误,服务端日志必须是首选检查点。
    可借助sshd -d启用debug模式来排查问题。
    可以用ssh -vvv以便更快找到问题。

    更多报错处理方法可以参考:https://segmentfault.com/a/1190000018629266

  • 相关阅读:
    第八章 路由器交换机及其操作系统的介绍
    k-Tree DP计数
    Drop Voicing 最长升序
    高精度
    1196D2
    C
    POJ 3974 马拉车
    2020.8.1第二十六天
    2020.7.31第二十五天
    每日日报
  • 原文地址:https://www.cnblogs.com/zyd112/p/11586496.html
Copyright © 2011-2022 走看看