1. 程式人生 > 其它 >升級ssh到最新版本

升級ssh到最新版本

技術標籤:軟體安裝

參考文章:

ssh對ssl是具有依賴關係的,需要檢查這兩者目前的版本

檢查ssh的版本:

ssh -V

檢查ssl版本:

openssl version

執行情況:

在這裡插入圖片描述

在openssh-8.4p1的INSTALL檔案有ssh和ssl版本對應關係,以8.4的為例:

libcrypto from either of LibreSSL or OpenSSL.  Building without libcrypto
is supported but severely restricts the available ciphers and algorithms.
 - LibreSSL (https://www.libressl.org/)
 - OpenSSL (https://www.openssl.org) with any of the following versions:
   - 1.0.x >= 1.0.1 or 1.1.0 >= 1.1.0g or any 1.1.1

經過分析,我們並不需要升級ssl,只需要升級ssh,所以本文只升級ssh

注意:貿然升級ssl是不可行的,可能會導致已安裝的應用依賴ssl不可用,具體參考連結2給出瞭如何正確升級ssl,然後升級ssh。

升級SSH

1、開啟telnet訪問

為了防止升級過程中通過ssh連線不到伺服器,所以有必要留一條備用的連線方式。

升級方式文章1已做講述,不再贅述

但是注意的是

1、開啟telnet服務之後,可以使用ssh的使用者名稱和密碼進行telnet登入連線測試

2、關閉telnet伺服器的防火牆,否則連不上

2、升級ssh

1、下載ssh相應的安裝包

2、升級需要幾個元件,有些是和編譯相關的等

yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel  pam* zlib*

3、解壓ssh安裝包

[[email protected] tools]# tar xfz openssh-8.4p1.tar.gz

4、給資料夾授予root許可權

[[email protected] tools]# chown -R root.root /data/tools/openssh-8.4p1

5、將之前的ssh目錄備份,然後新建一個ssh目錄

mv /etc/ssh /etc/ssh.old
mkdir
/etc/ssh

6、進入openssh-8.4p1,檢查、編譯、安裝

[[email protected] tools]#  cd openssh-8.4p1
[[email protected] openssh-8.4p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

# 檢查是否安裝成功,輸出0成功
[[email protected] openssh-8.4p1]# echo $?
0

如果openssl是通過編譯安裝的,那麼它的安裝位置應該不在預設的位置,所以在安裝openssh時需要指定openssl的安裝位置:

./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  && make && make install

7、修改配置檔案的內容為

[[email protected] ~]# grep "^PermitRootLogin"  /etc/ssh/sshd_config
PermitRootLogin yes
[[email protected] ~]# grep  "UseDNS"  /etc/ssh/sshd_config
UseDNS no
[[email protected] ~]#

這裡是指/etc/ssh/sshd_config這個檔案的內容配置確保正確,如果不是的話需要進行修改來和上面執行的結果保持一致

8、對ssh服務進行一些配置

# 如果存在則覆蓋
[[email protected] openssh-8.4p1]# cp -af contrib/redhat/sshd.init /etc/init.d/sshd
[[email protected] openssh-8.4p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[[email protected] openssh-8.4p1]# chmod +x /etc/init.d/sshd
[[email protected] openssh-8.4p1]# chkconfig --add sshd
[[email protected] openssh-8.4p1]# systemctl enable sshd
sshd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig sshd on

# 把原先的systemd管理的sshd檔案刪除或者移走或者刪除,不移走的話影響我們重啟sshd服務,沒有的話就不用管
[[email protected] ~]# mv  /usr/lib/systemd/system/sshd.service  /data/
#設定sshd服務開機啟動
[[email protected] ~]# chkconfig sshd on

9、測試服務的啟停

# 啟動
    /etc/init.d/sshd start
或
systemctl start sshd
# 關閉
/etc/init.d/sshd stop
或
systemctl stop sshd
# 重啟
/etc/init.d/sshd restart
或
/etc/init.d/sshd start

10、檢視ssh的版本,使用ssh工具測試連線是否正常,沒問題關閉telnet服務

# 檢視ssh的版本
ssh -V
# 關閉telnet
[[email protected] ~]#  systemctl disable xinetd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service.
[[email protected] ~]# systemctl stop xinetd.service
[[email protected] ~]# systemctl disable telnet.socket
Removed symlink /etc/systemd/system/sockets.target.wants/telnet.socket.
[[email protected] ~]# systemctl stop telnet.socket
[[email protected] ~]#  netstat -lntp