天天看点

Centos 6.5升级openssh到7.9p1

前言:

近期因centos 6.x 默认openssh扫描存在大量漏洞,基于安全考虑,需要将openssh_5.3p1升级为最新版,网上查了很多教程,发现openssh存在大量依赖,不解决依赖问题很难保证其他服务。而openssl又被大量程序依赖。实在是头疼。最后发现一个不破坏各种依赖又可以完美升级的方案。

以下操作系统是centos6.5

开启telnet
##安装telnet
yum -y install telnet-server*
service iptables stop
chkconfig iptables off
sed -i 's/\(.*\)disable\(.*\)/\ \ \ \ \ \ \ \ disable\ \ \ \ \ \ \ \ \ =\ no/g'   /etc/xinetd.d/telnet  ##将其中disable字段的yes改为no以启用telnet服务  
mv /etc/securetty /etc/securetty.old   #允许root用户通过telnet登录
service xinetd start
chkconfig xinetd on
           
检查环境

官方给出的文档中提到的先决条件openssh安装依赖zlib1.1.4并且openssl>=1.0.1版本就可以了。那么直接看当前系统的openssl版本是多少

[[email protected] ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[[email protected] ~]# rpm -q zlib
zlib-1.2.3-29.el6.x86_64
[[email protected] ~]# rpm -q zlib-devel
zlib-devel-1.2.3-29.el6.x86_64
           

发现自带的openssl版本符合openssh7.9p1的安装条件,自带的zlib也符合OpenSSH7.9P1的依赖。那么就直接安装吧

安装相关组件并升级openssh
yum install -y gcc openssl-devel pam-devel rpm-build pam-devel 
#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
rpm -e `rpm -qa | grep openssh` --nodeps
cd /usr/local/src/ && tar zxvf openssh-7.9p1_Compile.tar.gz &&  cd openssh-7.9p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers && make && make install
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin\ yes/g' /etc/ssh/sshd_config #或手动修改PermitRootLogin no 修改为 PermitRootLogin yes 允许root远程登陆
sed -i 's/#PermitEmptyPasswords\(.*\)/PermitEmptyPasswords\ no/g' /etc/ssh/sshd_config  ##禁止空密码
sed -i 's/^SELINUX\(.*\)/SELINUX=disabled/g' /etc/selinux/config  ##重点来了~~~禁止selinux 否则重启后会登录失败
echo 'KexAlgorithms [email protected],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支持的算法
cp contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
service sshd start
service sshd restart
chkconfig --list sshd
ssh -V
           
关闭telnet
mv /etc/securetty.old /etc/securetty   #允许root用户通过telnet登录
service xinetd stop
chkconfig xinetd off
service iptables start
chkconfig iptables on
将之前改过的disable=yes又改回去成no.
随后再将修改iptables将23端口关闭,并重启iptables服务.
至此,可以再开ssh登录,用ssh -V查看版本号.
           

继续阅读