Redhat、centos下openssh舊版本升級到openssh7.4

一、前提:
公司安全掃描掃出ssh漏洞,需升級openssh到7版本及以上。有1000+服務器,Redhat6.2/6.4/6.5 centos6.4/6.5/7.1/7.4。可以說是很複雜。無奈寫出100+行腳本批量執行。

二、腳本內容。
#!/bin/bash
############## yum源必須配置好 ###############
yum install -y gcc openssl-devel pam-devel rpm-build
if [ $? -ne 0 ]; then
echo "Please check your software source!"
exit
fi

#必須root用戶
if [  "whoami" != "root"];then
        echo "Installtion this package needs root user."
        exit 1
        fi

#---------------              關閉selinux               --------------
setenforce 0 
#file exist problem
if [ ! -f /tmp/zlib-1.2.11.tar.gz  ];then
    echo "The sources of zlib-1.2.11.tar.gz is not exist."
        exit
        fi

cd /tmp; tar xzf /tmp/zlib-1.2.11.tar.gz

#測試是否解壓成功

if [ ! -d /tmp/zlib-1.2.11 ];then
    echo "zlib-1.2.11.tar.gz is not uncompressed."
        exit
fi

#編譯安裝zlib

cd /tmp/zlib-1.2.11
/tmp/zlib-1.2.11/configure --prefix=/usr/local/zlib
make && make install
#編譯安裝openssl
#file exist problem
if [ ! -f /tmp/openssl-1.0.2n.tar.gz  ];then
    echo "The sources of openssl-1.0.2n.tar.gz is not exist."
        exit
fi
cd /tmp; tar xzf /tmp/openssl-1.0.2n.tar.gz

#test tar right or not

if [ ! -d /tmp/openssl-1.0.2n ];then
    echo "openssl-1.0.2n.tar.gz is not uncompressed."
        exit
fi
cd /tmp/openssl-1.0.2n
./config --prefix=/usr/local/openssl --shared
make
make test 
if [ $? -ne 0 ]; then
    echo "fail"
        exit
fi
make install   /tmp/zlib-1.2.11/openssl-1.0.2n/apps

cp -dpr /tmp/openssl-1.0.2n/apps/openssl /usr/bin/openssl
mkdir -p /usr/local/ssl/lib; chmod 755 -R /usr/local/ssl/lib
cp -dpr /tmp/openssl-1.0.2n/libssl.so* /usr/local/ssl/lib/
cp -dpr /tmp/openssl-1.0.2n/libcrypto.so* /usr/local/ssl/lib/
chmod 755 -R /usr/local/ssl; chmod 755 -R /usr/local/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf; ldconfig

sleep 3
#file exist problem
if [ ! -f /tmp/openssh-7.4p1.tar.gz  ];then
    echo "The sources of openssh-7.4p1.tar.gz is not exist."
        exit
fi
cd /tmp; tar xzf /tmp/openssh-7.4p1.tar.gz

#test tar right or not

if [ ! -d /tmp/openssh-7.4p1 ];then
    echo "openssh-7.4p1.tar.gz is not uncompressed."
        exit
fi
cd /tmp/openssh-7.4p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/openssl --with-md5-passwords --without-hardening 

make && make install

if [ $? -ne 0 ]; then
    echo "fail"
        exit
fi

cp -r /tmp/openssh-7.4p1/contrib/redhat/sshd.init /etc/init.d/sshd
chmod u+x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on 

sed -i '/^GSSAPICleanupCredentials/s/GSSAPICleanupCredentials yes/#GSSAPICleanupCredentials yes/' /etc/ssh/sshd_config
sed -i '/^GSSAPIAuthentication/s/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/' /etc/ssh/sshd_config
sed -i '/^GSSAPIAuthentication/s/GSSAPIAuthentication no/#GSSAPIAuthentication no/' /etc/ssh/sshd_config

service sshd restart

SSHD_version="OpenSSH_7.4p1, OpenSSL 1.0.1e-fips 11 Feb 2013"
LAST_version=`ssh -V`

if [ "$SSHD_version" -ne "$LAST_version"]; then
    echo "Upgrade faild"
else
    echo "Upgrade success"
fi

#centos7及上需執行下yum remove openssh -y systemd會與service衝突導致sshd啓不來

一鍵升級,完全沒有問題。

三、排坑指南:
1、
需注意的是centos7和centos6還是有區別的。centos7需要yum remore openssh -y。
啓動過程中如果發現/usr/bin或者是/usr/sbin 沒有相關的命令,可以去/tmp/openssh-7.4p1/下找到相關的命令cp到對應的目錄下。

2、
sshd啓動報錯:

Unsupported option GSSAPIAuthentication
Unsupported option GSSAPICleanupCredentials

解決方法:
註銷sshd的配置文件(sshd_config)的如下配置:

#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
#UsePAM yes

然後重啓服務:service sshd restart

3、centos7 報錯
Dec 21 15:48:32 sshd[21833]: Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
Dec 21 15:48:32 sshd[21833]: It is required that your private key files are NOT accessible by others.
Dec 21 15:48:32 sshd[21833]: This private key will be ignored.
Dec 21 15:48:32 sshd[21833]: key_load_private: bad permissions
Dec 21 15:48:32 sshd[21833]: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Dec 21 15:48:32 sshd[21833]: sshd: no hostkeys available -- exiting.
Dec 21 15:48:32 systemd[1]: Failed to start OpenSSH server daemon.
Dec 21 15:48:32 systemd[1]: Unit sshd.service entered failed state.
Dec 21 15:48:32 systemd[1]: sshd.service failed.

解決:
cd /etc/ssh/
chmod 600 ./*

4、gitlab服務宕
我在升級centos7.4的時候因爲remove了openssh。導致openssh-server也被卸載掉。
知識點:gitlab依靠openssh-server,一旦卸載gitlab相應的服務也會被卸載掉。

解決:別慌三條條命令恢復。
yum install openssh-server -y
rpm -ivh gitlab-ce-9.0.1-ce.0.el7.x86_64.rpm
sudo gitlab-ctl start
安裝了openssh-server之後openssh的版本不受影響還是升級後的版本號。
Redhat、centos下openssh舊版本升級到openssh7.4

5、Redhat、centos下openssh舊版本升級到openssh7.4
這裏就是報錯找不到什麼就去/tmp/openssh-7.4p1拷貝什麼,然後修改即可。

6、xshell或CRT不能登錄
解決:清下之前的緩存,遠程工具保存的祕鑰已經不能用了。之前保存的連接文件不能用了。最好是
Redhat、centos下openssh舊版本升級到openssh7.4

7、xftp報錯找不到算法,不能連接
Redhat、centos下openssh舊版本升級到openssh7.4
1)對於xshell,點擊:屬性—類別—安全性—加密—編輯,將那些與aes相關的加密算法選上,就能基本上解決這個問題了。如果找不到這幾個選項,說明你要升級Xshell了。

2)對於Xftp,點擊:菜單文件—屬性—設置—>編輯加密算法,將aes相關的選項勾上。不行同樣也需要升級。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章