Centos7系統(tǒng)ssh默認(rèn)版本一般是OpenSSH7.4左右,低版本是有漏洞的而且是高危漏洞,在軟件交付和安全掃描上是過不了關(guān)的,一般情況需要升級OpenSSH的最新版本
今天詳細(xì)說下升級最新版本的處理過程(認(rèn)真看會發(fā)現(xiàn)操作很簡單,因為寫的操作很詳細(xì)...)
1、第一步通過telnet-server連接服務(wù)器
現(xiàn)在絕大多數(shù)服務(wù)器的操作連接基本都是走的SSH協(xié)議,也就是常用的22端口。在升級OpenSSH的過程中會卸載老版本,安裝新版本,也就意味著升級過程中如果出現(xiàn)了問題,你可能會永遠(yuǎn)連不上你的服務(wù)器了,最后只能重裝系統(tǒng)(在客戶服務(wù)器上踩過雷...)
如何避免這個問題呢,就是采用telnet協(xié)議(23端口)來連接服務(wù)器,這樣在SSH升級的過程中失敗也不會有影響,重來就完事了 ~
安裝telnet-server服務(wù)
#telnet服務(wù)是由xinetd管理的,需要安裝xinetd服務(wù)才能啟動telnet-server
yum -y install telnet-server xinetd
#添加telnet配置文件
echo "service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}" > /etc/xinetd.d/telnet
#啟動xinetd
systemctl start xinetd
#開機自啟xinetd (開機自啟最好加上,升級完成SSH之后。會有重啟環(huán)節(jié),為防止意外服務(wù)最好自啟 后續(xù)升級完成再關(guān)閉就行)
systemctl enable xinetd
服務(wù)安裝完成,創(chuàng)建新用戶用來登錄telnet
#telnet本身拒絕root用戶遠(yuǎn)程登錄,最好用普通用戶登錄 然后su 到root賬戶
#創(chuàng)建賬號
useradd test
#設(shè)置密碼
passwd test
用telnet方式連接登錄服務(wù)器
[root@jinzhi01 ~]# telnet 192.168.0.200
Trying 192.168.0.200...
Connected to 192.168.0.200.
Escape character is '^]'.
Kernel 3.10.0-862.el7.x86_64 on an x86_64
jinzhi01 login: test
Password:
Last login: Sat Dec 2 22:44:45 from jinzhi01
[test@jinzhi01 ~]$ su
密碼:
[root@jinzhi01 test]#
到這里telnet網(wǎng)絡(luò)連接就安裝完成了,安全部分已經(jīng)得到保障,后續(xù)所有操作 都可以在telnet連接下進(jìn)行(你會發(fā)現(xiàn)和SSH協(xié)議 除了登錄有點區(qū)別,操作都是一樣的)
2、安裝openssl和zlib
升級OpenSSH需要先安裝最新版的openssl和zlib
openssl地址https://www.openssl.org/source/
zlib地址https://www.zlib.net/OpenSSH: for OpenBSDOpenSSH for OpenBSDhttps://www.openssh.com/openbsd.html下載安裝包
#進(jìn)入源碼存放目錄
cd /usr/local/src/
#下載openssh最新安裝包
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.5p1.tar.gz
#下載ssl
wget https://www.openssl.org/source/openssl-3.2.0.tar.gz --no-check-certificate
#下載zlib
wget https://www.zlib.net/zlib-1.3.tar.gz
安裝zlib
cd /usr/local/src/
#解壓文件
tar zxvf zlib-1.3.tar.gz
cd zlib-1.3
#安裝前置依賴
yum install gcc gcc-c++ make -y
#編譯安裝zlib
./configure --prefix=/usr/local/zlib
make && make install
安裝openssl文章來源:http://www.zghlxwxcb.cn/news/detail-813954.html
cd /usr/local/src/
#解壓文件
tar zxvf openssl-3.2.0.tar.gz
cd openssl-3.2.0
#安裝相應(yīng)的前置依賴
yum install -y perl-CPAN perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
#--prefix指定編譯到的目錄,"shared"作用是生成動態(tài)鏈接庫(即.so庫)
./config --prefix=/usr/local/ssl --shared
#編譯安裝ssl,這個安裝過程很長大概有10分鐘左右
make && make install
#路徑寫入etc/ld.so.conf
echo '/usr/local/ssl/lib64' >> /etc/ld.so.conf
3、備份并卸載老版本OpenSSH
#備份ssh配置文件
cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp -p /usr/sbin/sshd /usr/sbin/sshd.bak
cp -p /usr/bin/ssh /usr/bin/ssh.bak
cp -p /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -p /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
#停止ssh服務(wù)
systemctl stop sshd
#備份ssh文件
cp -r /etc/ssh /etc/ssh.old
#查詢原有ssh包并卸載
rpm -qa | grep openssh
openssh-7.4p1-23.el7_9.x86_64
openssh-clients-7.4p1-23.el7_9.x86_64
openssh-server-7.4p1-23.el7_9.x86_64
#根據(jù)查詢結(jié)果,卸載原有OpenSSH包
yum remove openssh-7.4p1-23.el7_9.x86_64
#再次查看已經(jīng)沒有了
rpm -qa | grep openssh
4、升級OpenSSH
cd /usr/local/src/
#解壓
tar zxvf openssh-9.5p1.tar.gz
cd openssh-9.5p1
#編譯安裝openssh 指明zlib路徑和ssl路徑
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install
#ssh允許root登錄、需要密碼進(jìn)行驗證
echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config
#將編譯安裝的新配置文件 拷貝到原路徑下
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
#拷貝啟動腳本
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
#給sshd添加可執(zhí)行權(quán)限
chmod +x /etc/init.d/sshd
#設(shè)置開機自啟
systemctl enable sshd
#重新啟動sshd服務(wù)
systemctl restart sshd
#查看sshd服務(wù)狀態(tài)
systemctl status sshd
#查看ssh版本是否升級成功,可以查看到已經(jīng)是9.5版本了
ssh -V
OpenSSH_9.5p1, OpenSSL 3.2.0 23 Nov 2023
到這里升級基本完成了,可以通過reboot重啟服務(wù)器 用來校驗相關(guān)的自啟服務(wù) ~文章來源地址http://www.zghlxwxcb.cn/news/detail-813954.html
到了這里,關(guān)于OpenSSH 漏洞修復(fù)升級最新版本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!