一、背景:
公司安全掃描到主機(jī)的OpenSSH安全漏洞,由于是虛擬機(jī)只能由自己修復(fù),很多OpenSSH的漏洞廠商都沒有提供補(bǔ)丁,只能通過禁用scp或者端口的方式臨時(shí)解決,但是后面使用就不方便了,而且也不安全,所以直接將OpenSSH升級(jí)到現(xiàn)在的最高版本openssh-9.3p2,ssl升級(jí)到1.1.1。
?二、準(zhǔn)備工作:
升級(jí)OpenSSH是有風(fēng)險(xiǎn)的,失敗會(huì)導(dǎo)致不能通過SSH連接到主機(jī),所以最好先按照telnet的相關(guān)工具,通過telnet連接主機(jī)進(jìn)行SSH升級(jí)操作,因?yàn)榇舜尾僮鞯氖翘摂M機(jī),跟公司的機(jī)房老師溝通,即使升級(jí)失敗,他們也是可以連接上主機(jī)的,所有我就沒再按照telnet的相關(guān)組件,直接通過SSH連接到主機(jī)進(jìn)行的升級(jí)。升級(jí)前可以先看下報(bào)錯(cuò)處理章節(jié),方便安裝過程中有問題解決。
升級(jí)SSH需要先查看gcc、pcre、zlib??perl是否安裝使用以下命令可以查看:
gcc --version、rpm -qa pcre、yum list installed | grep zlib*、perl -version。查看SSH版本 ssh -V, 查看ssl版本openssl version
?
gcc包沒有的請(qǐng)參考這篇文章:https://blog.51cto.com/u_15064655/4818120
perl沒有的:
下載地址:https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz,將包上傳到服務(wù)器上,然后執(zhí)行一下命令:
tar?-xzf perl-5.34.0.tar.gz
?cd?perl-5.34.0
./Configure -des -Dprefix=$HOME/localperl
make?
make?test?
make?install
注意:
1、通過SSH連接主機(jī)升級(jí)時(shí),不要關(guān)閉SSH連接,再升級(jí)過程中關(guān)閉了以后可能就連不上了;
2、SSH升級(jí)依賴于SSL,對(duì)SSL的版本有要求,要先按照SSL再按照SSH;
三、開始安裝:
1、下載openssl、openssh、zlib包
下載openssl
https://www.openssl.org/source/openssl-1.1.1t.tar.gz
下載openssh
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p2.tar.gz
下載zlib
http://www.zlib.net/zlib-1.2.13.tar.gz
按照順序是zlib庫-> openssl -> openssh的順序安裝;
2、安裝zlib
tar?-zxvf?zlib-1.2.13.tar.gz???-C /usr/local/src
cd zlib-1.2.13
./configure --prefix=/usr/local/zlib &&?make?-j 4?&&?make?install
3、安裝ssl
tar -zxvf openssl-1.1.1t.tar.gz -C /usr/local/src/
cd /usr/local/src/openssl-1.1.1t
./config --prefix=/usr/local/ssl -d shared? #編譯時(shí)可能會(huì)報(bào)錯(cuò),請(qǐng)看錯(cuò)誤模塊
make -j 4 && make install
?echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v
/usr/local/ssl/bin/openssl version -a # 查詢這個(gè)目錄下openssl版本已是1.1.1p
4、安裝ssh
tar -zxvf openssh-9.3p1.tar.gz -C /usr/local/src/
先備份:mv /etc/ssh /etc/ssh.bak
cd ?/usr/local/src/openssh-9.3p2
#指定ssl和zlib安裝位置
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib
make -j 4 && make install
#修改配置文件sshd_config文件修改
echo "X11Forwarding yes" >> /etc/ssh/sshd_config
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config
echo "UseDNS no" >> /etc/ssh/sshd_config
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
#備份 /etc/ssh 原有文件,并將新的配置復(fù)制到指定目錄
mv /usr/sbin/sshd /usr/sbin/sshd.bak
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh?
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
安裝完成,查看版本ssh -V
5、重啟sshd服務(wù)
systemctl restart sshd
systemctl status sshd
四、報(bào)錯(cuò)處理:
1、執(zhí)行ssl的./config --prefix=/usr/local/ssl -d shared編譯時(shí)報(bào)錯(cuò):
Operating system: x86_64-whatever-linux2?You need Perl 5.
你需要安裝perl-5.34.0.tar.gz,
下載https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz
tar?-xzf perl-5.34.0.tar.gz
?cd?perl-5.34.0
./Configure -des -Dprefix=$HOME/localperl
make?
make?test?
make?install
2、ssl 執(zhí)行 ?make -j 4 && make install報(bào)錯(cuò)
sh: pod2html: command not found
沒找到原因,但是暫時(shí)沒找到有什么影響,測試ssl是正常的。
3、重啟ssh服務(wù)報(bào)錯(cuò):
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.????????
使用/usr/sbin/sshd -T查看
是/etc/ssh/ssh_host_ed25519_key這個(gè)文件的權(quán)限太大了,去所在目錄下執(zhí)行 chmod 600 ssh_host_ed25519_key 命令修改文件權(quán)限,重啟可能還報(bào)錯(cuò),再用-T看下,還有其他的文件權(quán)限太大。
chmod 600 ssh_host_rsa_key、chmod 600 ssh_host_ecdsa_key、 chmod 600 ssh_host_ed25519_key基本上這三個(gè)。
4、重啟報(bào)錯(cuò):Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.?
用sshd -t看到報(bào)錯(cuò)信息為
/etc/ssh/sshd_config line 80: Unsupported option GSSAPICleanupCredentials
/etc/ssh/sshd_config line 96: Unsupported option UsePAM
文章來源:http://www.zghlxwxcb.cn/news/detail-613859.html
vi /etc/ssh/sshd_config
把#GSSAPIAuthentication yes??、#GSSAPICleanupCredentials no??把這兩個(gè)禁掉
#UsePAM no也禁掉文章來源地址http://www.zghlxwxcb.cn/news/detail-613859.html
到了這里,關(guān)于linux系統(tǒng)將OpenSSH升級(jí)到最高版本的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!