Centos7.x操做升級openssh8.6p1

備註:
ssh服務是linux服務器管理的關鍵入口,升級必定要注意在測試環境多加驗證,確保升級過程萬無一失,避免因升級失敗而致使失去對服務器的控制。

強烈建議升級期間開啓telnet服務:node

配置telnet登陸

一、安裝telnet-server以及xinetdlinux

[root@k8s-master ~]# yum -y install xinetd telnet-server

二、配置telnet(若是下面文件不存在,能夠跳過這部分的更改;若是下面文件存在,請更改配置telnet能夠root登陸,把disable = no改爲disable = yes)bash

[root@k8s-master ~]# ll /etc/xinetd.d/telnet

#輸出以下結果,表示沒有此配置文件,修改/etc/xinetd.d/telnet配置可跳過服務器

[root@k8s-master ~]# ls: cannot access /etc/xinetd.d/telnet: No such file or directory
[root@k8s-master ~]# cat /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#   unencrypted username/password pairs for authentication.
service telnet
{
    disable = yes
    flags       = REUSE
    socket_type = stream       
    wait        = no
    user        = root
    server      = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}

三、配置telnet登陸的終端類型markdown

[root@k8s-master ~]# cat >>/etc/securetty<<EOF
pts/0
pts/1
pts/2
pts/3
EOF
[root@k8s-master ~]# tail -5 /etc/securetty
xvc0
pts/0
pts/1
pts/2
pts/3

四、啓動telnet服務,並設置開機自動啓動網絡

[root@k8s-master ~]# systemctl enable xinetd && systemctl enable telnet.socket
[root@k8s-master ~]# systemctl start telnet.socket && systemctl start xinetd
[root@k8s-master ~]# netstat -lntp|grep 23
[root@k8s-master ~]# firewall-cmd --add-port=23/tcp --zone=public --permanent
[root@k8s-master ~]# firewall-cmd --reload

五、切換到telnet方式登陸,之後的操做都在telnet終端下操做,防止ssh鏈接意外中斷形成升級失敗session

一、查看當前服務器ssh版本相關信息

[root@k8s-master ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
[root@k8s-master ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

二、首先機器聯網安裝升級相關依賴包

[root@k8s-master ~]# yum -y install wget gcc zlib-devel openssl-devel pam-devel libselinux-devel

三、升級OPENSSL

3.一、備份舊版openssl

[root@k8s-master ~]# mv /usr/bin/openssl{,.bak}
[root@k8s-master ~]# mv /usr/include/openssl{,.bak}

3.二、下載openssl-1.1.1k包,解壓並編譯安裝

openssl-1.1.1k.tar.gz下載地址app

[root@k8s-master ~]# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
[root@k8s-master ~]# tar zxf openssl-1.1.1k.tar.gz -C /usr/local/
[root@k8s-master ~]# cd /usr/local/openssl-1.1.1k/
[root@k8s-master openssl-1.1.1k]# ./config --prefix=/usr/local/openssl
[root@k8s-master openssl-1.1.1k]# make -j 2 && make install

3.三、建立相應的軟連接及版本驗證

[root@k8s-master openssl-1.1.1k]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@k8s-master openssl-1.1.1k]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@k8s-master openssl-1.1.1k]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@k8s-master openssl-1.1.1k]# ldconfig -v
[root@k8s-master openssl-1.1.1k]# openssl version
OpenSSL 1.1.1k  25 Mar 2021

四、關鍵步驟:升級OPENSSH

4.一、中止原有服務並備份相關文件

[root@k8s-master ~]# systemctl stop sshd
[root@k8s-master ~]# mv /etc/ssh{,.bak}
[root@k8s-master ~]# mv /etc/pam.d/sshd{,.bak}

4.二、卸載舊版本openssh包

強烈建議經過網絡找到openssh的rpm包,以免升級失敗時,找不到相應的安裝包ssh

[root@k8s-master ~]# rpm -e --nodeps `rpm -qa | grep openssh`

4.三、下載openssh8.6p1並解壓安裝包

openssh-8.6p1.tar.gz下載地址socket

[root@k8s-master ~]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
[root@k8s-master ~]# tar zxf openssh-8.6p1.tar.gz 
[root@k8s-master ~]# cd openssh-8.6p1

4.四、安裝升級

[root@k8s-master openssh-8.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --without-hardening
[root@k8s-master openssh-8.6p1]# make -j 2 && make install

4.五、拷貝配置ssh相關文件並啓動服務

[root@k8s-master openssh-8.6p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@k8s-master openssh-8.6p1]# mv /etc/pam.d/sshd.bak /etc/pam.d/sshd
[root@k8s-master openssh-8.6p1]# mv /etc/ssh /etc/ssh_update.bak
[root@k8s-master openssh-8.6p1]# mv /etc/ssh.bak /etc/ssh
[root@k8s-master openssh-8.6p1]# chmod 600 /etc/ssh/*key
[root@k8s-master openssh-8.6p1]# chkconfig --add sshd
[root@k8s-master openssh-8.6p1]# chkconfig sshd on
[root@k8s-master openssh-8.6p1]# systemctl restart sshd

4.六、修改配置文件容許Root登錄與版本驗證

[root@k8s-master ~]# sed -i 's/^#\(PermitRootLogin \).*/\1yes/' /etc/ssh/sshd_config
[root@k8s-master openssh-8.6p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1k  25 Mar 2021

有可能遇到的問題及相應的解決辦法:

問題:
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
解決:
[root@k8s-master ~]# grep sshd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp
相關文章
相關標籤/搜索