1.因公司服务器被绿盟扫描出openssl、openssh漏洞,所以需要升级openssl、openssh
2.操作系统:Red Hat Enterprise Linux Server release 7.2 (Maipo)
软件升级版本:openssl-1.0.2k.tar.gz、openssh-7.4p1.tar.gz
3.升级出现问题,编译安装openssh后,不会自动生成sshd.service等systemctl启动服务的文件,故提前做了备份,但觉得应该有其他的方法可以解决,希望大家提供宝贵意见
4.升级脚本根据孙磊博客脚本改编而来(),安装时将脚本和两个包放在相同路径下,解决依赖请配置好YUM仓库
5.脚本updatessh.sh
#!/bin/bash#-------------------------------------|#"WARING"!!! Please use telnet-server.|#"WARING"!!! Please use telnet-server.|#"WARING"!!! Please use telnet-server.|#-------------------------------------|ssh_update(){#Backup the old filesSSL_VER=openssl-1.0.2kSSH_VER=openssh-7.4p1CUR_DIR=$(pwd)SSH_DIR=/usr/local/opensshmv /etc/ssh /etc/ssh_backupmkdir /tmp/sysdircp /usr/lib/systemd/system/sshd* /tmp/sysdir/cp /etc/sysconfig/sshd /tmp/sysdir/#Update sslyum -y install gcc gcc-c++ zlib-devel pam-devel tcp_wrappers*cd $CUR_DIRtar zxf $SSL_VER.tar.gzcd $SSL_VER./config shared zlibmake && make installmv /usr/bin/openssl /usr/bin/openssl.backupmv /usr/include/openssl /usr/include/openssl.backupln -s /usr/local/ssl/bin/openssl /usr/bin/opensslln -s /usr/local/ssl/include/openssl/ /usr/include/opensslecho "/usr/local/ssl/lib" >> /etc/ld.so.confldconfig/sbin/restorecon -v /usr/local/ssl/lib/libcrypto.so.1.0.0cd ..#Update sshdrpm -e `rpm -qa | grep openssh` --nodepstar zvxf $SSH_VER.tar.gzcd $SSH_VER/./configure --prefix=$SSH_DIR --sysconfdir=/etc/ssh --with-pam --with-tcp-wrappers \--with-ssl-dir=/usr/local/ssl --with-md5-passwords --with-zlib=zlibmake && make installcd $SSH_DIRmkdir /tmp/sshdircp -rf sbin/sshd /tmp/sshdir/mv -f /tmp/sshdir/sshd /usr/sbin/sshdcp -rf bin/* /tmp/sshdir/mv -f /tmp/sshdir/* /usr/bin/sed -i 's#/usr/libexec/sftp-server#/usr/local/openssh/libexec/sftp-server#' /etc/ssh/sshd_configsed -i '/#PermitRootLogin/aPermitRootLogin yes' /etc/ssh/sshd_configmv -f /tmp/sysdir/sshd /etc/sysconfig/sshdcp /tmp/sysdir/sshd* /usr/lib/systemd/system/systemctl reload sshdsystemctl enable sshdsystemctl restart sshd.service} read -p "Are you using telnet[YES/NO]?" ANSWERcase $ANSWER inYES) echo "Fine,continue!!!" ssh_update 2>&1 | tee -a /tmp/update.log ;;NO) echo "It is dangerous,bye!!!";;*) echo "Error choice";;esac