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

posted on 2019-09-25 18:10  Noway11 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/zyd112/p/11586496.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值