centos7升級openssl、openssh常見問題及解決方法


升級至openssl 1.1.1版本

升級至openssh 8.0版本

 

openssl version -a   當前查看版本

 

一.安裝telnet (以防升級失敗,連不上服務器,建議弄)

# 查看是否安裝telnet服務
rpm -qa | grep telnet rpm -qa | grep xinetd

# 若無安裝,yum安裝

yum -y install telnet* 

yum -y install xinetd

 

#將服務開機自啟(此處根據自身情況考慮)

systemctl enable xinetd.service

systemctl enable telnet.socket

 

#開啟服務

systemctl start telnet.socket  

systemctl start xinetd

 

 vi /etc/securetty

在最后添加兩行

pts/0

pts/1

 

systemctl restart xinetd

netstat -plnt |grep 23  # 確認下是否啟動成功

 

二、升級OpenSSl

1、查看原版本

openssl version -a

 

 2、解壓安裝

tar zxvf openssl-1.1.1c.tar.gzcd openssl-1.0.1g

cd openssl-1.1.1c

./config --prefix=/usr/local/openssl  #檢查環境

./config –t

make     #編譯

make install      #編譯安裝

 

cd /usr/local

ldd /usr/local/openssl/bin/openssl    #檢查函數庫

echo "/usr/local/openssl/lib" >> /etc/ld.so.conf    #添加所缺函數庫

ldconfig -v        #更新函數庫

openssl/bin/openssl version      #查看新安裝的版本

 

which openssl           #查看舊版本openssl命令在哪里

mv /bin/openssl /usr/bin/openssl.old      #將舊版本openssl移除

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl           #新版本制作軟鏈接

openssl version         最后查看版本,更新完畢

在確保Openssl版本為1.0.1后,可以升級Openssh了,升級方法如下。

 

三、升級openssh

1、同樣第一步解壓,不再贅述

 

2、移除舊版本

mv /etc/ssh /etc/ssh.old
### 需要注意,移除之后,不能退出當前終端,若退出,只能通過telnet連了

 

3、編譯安裝

cd openssh-8.0p1/

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening

報錯1:

在安裝的過程中如遇到以下錯誤,請安裝:yum -y install openssl-devel

 

 

報錯2:configure: error: PAM headers not found 

請安裝yum -y install pam-devel

 

我升級的時候只遇到這兩個錯,如遇到別的錯,請自行解決。

然后編譯安裝

make && make install 

 

4、修改啟動腳本

# 拷貝啟動腳本
cp
./contrib/redhat/sshd.init /etc/init.d/sshd

# 修改啟動腳本
vim /etc/init.d/sshd

# 按如下圖修改,需要注意,此路徑是你安裝新版本的openssh路徑,根據你的實際情況修改
SSHD=/usr/local/openssh/sbin/sshd

 

 

### 注意根據自身情況修改路徑
/usr/local/openssh/bin/ssh-keygen –A /sbin/restorecon /etc/ssh/ssh_host_key.pub /sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub /sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub /sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub

 

 

5、修改sshd配置文件/etc/ssh/sshd_config 

 

echo "PermitRootLogin yes" >> /etc/ssh/sshd_config    #直接用root登錄終端(此處根據自身情況考慮)

echo 'X11Forwarding yes' >> /etc/ssh/sshd_config   #設置是否允許X11轉發

echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config   #是否允許密碼驗證

 

 

6、卸載原有ssh(先安裝后卸載,也是怕升級失敗,如果有把握,可先卸載)

for  i   in  $(rpm  -qa  |grep  openssh);do  rpm  -e  $i  --nodeps ;done

提示警告:

 

 

將警告中被修改的文件名字再改回來

mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config

mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config

mv /etc/ssh/moduli.rpmsave /etc/ssh/moduli

 

 7、替換相關命令,並重啟sshd服務

cp -arp /usr/local/openssh/bin/* /usr/bin/  替換相關命令

service sshd restart   重啟sshd服務

 

驗證升級、讓其他人測試連接后再退出

ssh -V 和telnet 

 

 

8、設置開機自啟

chkconfig --add sshd

chkconfig --level 2345 sshd on

chkconfig --list 

 

升級完成后,為了安全起見,建議關閉telnet

#關閉服務(此處根據自身情況考慮)

systemctl stop telnet.socket  

systemctl stop xinetd


#關閉服務開機自啟(此處根據自身情況考慮)

systemctl disable xinetd.service

systemctl disable telnet.socket

 

如有轉載請標明出處 謝謝


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM