系統環境
CentOS Linux release 7.6.1810 (Core)
OpenSSH_7.9p1, OpenSSL 1.0.2k-fips 26 Jan 2017
升級準備
-
在打開ssh連接工具(如xshell)的同時打開文件傳輸工具(如xftp)。因爲升級過程不能創建新的連接,以備手動上傳文件需要。
-
將要升級的軟件包預先下載好,如本次的
openssl-1.1.1c.tar.gz
、openssh-8.0p1.tar.gz
。待升級完成後刪除即可。Openssl: https://ftp.openssl.org/source/
任意進入一個個人目錄,使用wget下載:cd /tmp wget https://ftp.openssl.org/source/openssl-1.1.1c.tar.gz
Openssh: https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
任意進入一個個人目錄,使用wget下載:cd /tmp wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz
注意事項
將/usr/lib64
目錄下的libssl.so.1.0.2k
、libcrypto.so.1.0.2k
進行備份。在升級openssl過程中着兩個文件會被刪除,導致yum、wget、ping等諸多命令不能使用。
cd /usr/lib64
cp libssl.so.1.0.2k /bak #/bak爲備份目錄
cp libcrypto.so.1.0.2k /bak
關閉selinux
臨時關閉:setenforce 0
# 採用臨時關閉即可
永久關閉:vi /etc/sysconfig/selinux
SELINUX=enforcing
改爲 SELINUX=disabled
重啓服務 reboot
關閉防火牆
防火牆相關操作
- 查看防火牆狀態:
firewall-cmd –state
- 開啓防火牆:
firewall-cmd –reload #重載配置,不會斷開已有tcp會話。推薦使用 systemctl restart firewalld #重啓服務,會斷開已有tcp會話。不推薦
- 停止防火牆:
systemctl stop firewalld.service #建議升級過程中關閉
- 禁止開機啓動:
systemctl disable firewalld.service
- 開放指定端口(22爲例):
firewall-cmd --permanent --add-port=22/tcp
安裝telnet
ssh不能登錄時的備用登錄方案
- 安裝:
yum install xinetd telnet-server -y
- 配置telnet
vi /etc/xinetd.d/telnet
輸入以下內容# default: on # description: The telnet server serves telnet sessions; it uses \ # unencrypted username/password pairs for authentication. service telnet { # if allow root login, disable = yes disable = no flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID }
- 配置telnet登錄的終端類型,在
/etc/securetty
文件末尾增加一些pts終端,如下pts/0 pts/1 pts/2 pts/3
- 啓動telnet服務
systemctl enable xinetd systemctl enable telnet.socket Created symlink from /etc/systemd/system/sockets.target.wants/telnet.socket to /usr/lib/systemd/system/telnet.socket. systemctl start telnet.socket systemctl start xinetd netstat -lntp|grep 23 tcp6 0 0 :::23 :::* LISTEN 1/systemd
安裝依賴包(後面升級需要)
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
yum install -y pam* zlib*
升級openssl
cd /tmp
tar -zxvf openssl-1.1.1c.tar.gz
cd penssl-1.1.1c
./config --prefix=/usr/local/openssl #如果此步驟報錯,需要安裝perl以及gcc包
echo $? #查看上一步命令是否報錯
0
make
echo $? #查看上一步命令是否報錯
0
make install
echo $? #查看上一步命令是否報錯
0
mv /usr/bin/openssl /usr/bin/openssl.bak #備份
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl #創建軟連接
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf #寫入 openssl 庫文件的搜索路徑
ldconfig -v #設置/etc/ld.so.conf生效
openssl version
OpenSSL 1.1.1c 28 May 2019
升級openssh
- 安裝
cp -r /etc/ssh /etc/ssh.bak #備份 cd /tmp tar -zxvf openssh-8.0p1.tar.gz cd openssh-8.0p1 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/openssl/include --with-ssl-dir=/usr/local/openssl --with-zlib --with-md5-passwords --with-pam #注意參數的路徑 echo $? #查看上一步命令是否報錯 0 make && make install echo $? #查看上一步命令是否報錯 0
- 配置
vi /etc/ssh/sshd_config 修改爲以下內容 PasswordAuthentication yes UseDNS no cd /tmp/openssh-8.0p1 mv /etc/init.d/sshd /etc/init.d/sshd.bak #備份 cp -a contrib/redhat/sshd.init /etc/init.d/sshd #使用新版本的執行文件 cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam #不存在就不管 sudo chmod +x /etc/init.d/sshd #添加執行權限,非root用戶安裝時需要 chkconfig --add sshd #將sshd服務設置爲開機啓動 systemctl enable sshd #允許sshd服務自啓動 mv /usr/lib/systemd/system/sshd.service /tmp #刪除或移除原來sshd文件。否則影響sshd服務重啓 systemctl restart sshd #重啓ssh服務。(修改服務配置後都需重啓,使配置生效) #一些內容爲可選 #修改默認端口 vi /etc/ssh/sshd_config 將Port 修改爲其他端口,如2222 firewall-cmd --permanent --add-port=2222/tcp #防火牆開放2222端口 firewall-cmd –reload #重啓防火牆
- 驗證
chkconfig sshd on #查看服務運行級別 #驗證是否正常啓動 /etc/init.d/sshd restart /etc/init.d/sshd stop /etc/init.d/sshd start systemctl restart sshd systemctl stop sshd systemctl start sshd netstat -lntp #查看sshd服務是否啓動以及監聽的端口(默認22) ssh -V OpenSSH_8.0p1, OpenSSL 1.1.1c 28 May 2019
修復升級帶來的問題
error while loading shared libraries: libssl.so.10: cannot open shared
。由於libssl.so 、libcrypto.so 等庫文件缺失,導致yum、ping、wget不能使用cd /usr/lib64 cp /u01/libssl.so.1.0.2k ./ cp /u01/libcrypto.so.1.0.2k ./ ln -s libssl.so.1.0.2k ./libssl.so #創建軟連接 ln -s libssl.so.1.0.2k ./libssl.so.10 ln -s libcrypto.so.1.0.2k ./libcrypto.so ln -s libcrypto.so.1.0.2k ./libcrypto.so.10
恢復升級之外的臨時配置
- 關閉telnet
確保重新使用ssh登錄沒問題後,關閉telnet服務。systemctl disable xinetd.service Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service. systemctl stop xinetd.service systemctl disable telnet.socket systemctl stop telnet.socket #查看telnet服務是否關閉,任選其一 netstat -lntp #查看23端口是否被監聽 netstat -antp #查看23端口是否被監聽 chkconfig –list #沒有telnet出現即可
- 恢復防火牆爲初始狀態