一,备份配置文件,以备升级失败进行回退
二,下载安装包
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget https://openbsd.mirror.netelligent.ca/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz
三,查看当前系统版本
四,开启telnet连接通道
yum安装telnet
yum -y install telnet-server*
关闭防火墙
/etc/init.d/iptables stop
编辑配置文件
vim /etc/xinetd.d/telnet
disable值yes改为no
允许root用户通过telnet登录
mv /etc/securetty /etc/securetty.old
启动并设置开机启动
/etc/init.d/xinetd start
chkconfig xinetd on
验证 telnet 127.0.0.1
五,安装编译工具包
yum install gcc pam-devel zlib-devel -y
六,安装zlib
解压
tar -xf zlib-1.2.11.tar.gz
进入目录
cd zlib-1.2.11
编译
./configure --prefix=/usr
make
卸载
rpm -e --nodeps zlib
make install
共享库文件注册到系统
echo ‘/usr/lib‘ >> /etc/ld.so.conf
ldconfig
七,升级openssl
备份当前openssl
mv /usr/lib64/openssl/ /usr/lib64/openssl.old
mv /usr/bin/openssl /usr/bin/openssl.old
mv /etc/pki/ca-trust/extracted/openssl /etc/pki/ca-trust/extracted/openssl.old
如下两个库文件必须先备份,因系统内部分工具(如yum、wget等)依赖此库,而新版OpenSSL不包含这两个库
cp /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.10.old
cp /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.10.old
卸载当前openssl
rpm -qa |grep openssl|xargs -i rpm -e --nodeps {}
安装openssl
tar -xf openssl-1.0.2m.tar.gz
cd openssl-1.0.2m
./config --prefix=/usr/local/ssl --openssldir=/etc/ssl --shared zlib
echo $?
make
make test
make install
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -v
验证
openssl version
PS:必须加上--shared,否则编译时会因找不到新安装的openssl的类库而报错
恢复共享库
mv /usr/lib64/libcrypto.so.10.old /usr/lib64/libcrypto.so.10
mv /usr/lib64/libssl.so.10.old /usr/lib64/libssl.so.10
八,升级openssh
备份当前openssh
mv /etc/ssh /etc/ssh.old
卸载
rpm -qa |grep openssh|xargs -i rpm -e --nodeps {}
openssh安装前环境配置
install -v -m700 -d /var/lib/sshd
chown -v root:sys /var/lib/sshd
groupadd -g 51 sshd
useradd -c ‘sshd PrivSep‘ -d /var/lib/sshd -g sshd -s /bin/false -u 51 sshd
源码安装
tar -xf openssh-7.4p1.tar.gz
cd openssh-7.4p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-ssl-dir=/usr/local/ssl --with-privsep-path=/var/lib/sshd
make && make install
安装后环境配置
install -v -m755 contrib/ssh-copy-id /usr/bi
install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
install -v -m755 -d /usr/share/doc/openssh-7.4p1
install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.4p1
验证是否安装成功
启动openssh服务
echo ‘X11Forwarding yes‘ >> /etc/ssh/sshd_config
允许root直接登录
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
拷贝启动文件设置chkconfig
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
重启sshd需要通过telnet才能登录启动sshd了
/etc/init.d/sshd restart
如果需要还原原来的ssh配置(如不需要则不进行一下操作)
rm -rf /etc/ssh
mv /etc/ssh.old /etc/ssh
验证 openssh已经升级为更加安全的高版本
参考:https://www.cnblogs.com/share100/p/6862635.html
http://www.cnblogs.com/ldybyz/p/6699779.html