SSH升級版本--8.2p1


前期准備

執行yum update  openssh先升級下.

反正官方提供的這種升級是沒問題的。如果之前手動編譯操作過openssh的升級,變更了默認配置文件路徑什么的請自行測試。)

(這里准備統一openssh版本為7.4p1之后再統一編譯安裝升級到openssh8.2p1)

[root@node1 ~]# yum update openssh -y

[root@node1 ~]# ssh -V

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

 

下載openssh以及openssl安裝包

openssl下載鏈接:https://www.openssl.org/source/

openssh下載鏈接:http://www.openssh.com/portable.html

 

安裝配置telnet

安裝telnet-server以及xinetd

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

現在很多centos7版本安裝telnet-server以及xinetd之后沒有一個叫telnet的配置文件了。

如果下面telnet文件不存在的話,可以跳過這部分的更改

[root@node1 ~]# ll /etc/xinetd.d/telnet
ls: cannot access /etc/xinetd.d/telnet: No such file or directory

 

如果下面文件存在,請更改配置telnet可以root登錄,把disable = no改成disable = yes

[root@rhel yum.repos.d]# 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 = no
    flags       = REUSE
    socket_type = stream        
    wait        = no
    user        = root
    server      = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}
 
[root@rhel yum.repos.d]# vim /etc/xinetd.d/telnet
[root@rhel yum.repos.d]# 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登錄的終端類型,在/etc/securetty文件末尾增加一些pts終端,如下

pts/0

pts/1

pts/2

pts/3

 

啟動telnet服務,並設置開機自動啟動

[root@node1 ~]# systemctl start xinetd
[root@node1 ~]# systemctl enable xinetd
[root@node1 ~]# systemctl start telnet.socket
[root@node1 ~]# systemctl enable telnet.socket
Created symlink from /etc/systemd/system/sockets.target.wants/telnet.socket to /usr/lib/systemd/system/telnet.socket

 

測試,切換到telnet登錄

 

 

 

安裝依賴包

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

[root@node1 ~]# yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel

安裝pam和zlib等(后面的升級操作可能沒用到pam,安裝上也沒啥影響,如果不想安裝pam請自行測試)

[root@node1 ~]# yum install  -y pam* zlib*

 

安裝openssl

備份下面2個文件或目錄(如果存在的話就執行)

[root@node1 openssl-1.1.1g]# ll /usr/bin/openssl 
-rwxr-xr-x 1 root root 555288 Aug  9  2019 /usr/bin/openssl
[root@node1 openssl-1.1.1g]# mv /usr/bin/openssl /usr/bin/openssl.20200522
[root@node1 openssl-1.1.1g]# ll /usr/include/openssl/
total 1864
-rw-r--r-- 1 root root   6146 Aug  9  2019 aes.h
-rw-r--r-- 1 root root  63204 Aug  9  2019 asn1.h
-rw-r--r-- 1 root root  24435 Aug  9  2019 asn1_mac.h
……
[root@node1 openssl-1.1.1g]# mv /usr/include/openssl /usr/include/openssl.20200522bak

編譯安裝新版本的openssl

配置、編譯、安裝3個命令一起執行

&&符號表示前面的執行成功才會執行后面的

[root@node1 openssl-1.1.1g]# pwd
/root/openssh/openssl-1.1.1g
[root@node1 openssl-1.1.1g]# ./config –prefix=/usr/local/openssl && make && make install

下面2個文件或者目錄做軟鏈接 (剛才前面的步驟mv備份過原來的)

[root@node1 openssl-1.1.1g]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@node1 openssl-1.1.1g]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@node1 openssl-1.1.1g]# ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so

 

命令行執行下面2個命令加載新配置

[root@node1 openssl-1.1.1g]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@node1 openssl-1.1.1g]# ldconfig

查看確認版本

[root@node1 openssl-1.1.1g]# openssl version
OpenSSL 1.1.1g  21 Apr 2020

 

安裝openssh 

解壓文件

[root@node1 openssh]# tar -xf openssh-8.2p1.tar.gz 
[root@node1 openssh]# cd openssh-8.2p1
[root@node1 openssh-8.2p1]# ll

可能文件默認顯示uid和gid數組都是1000,這里重新授權下。不授權可能也不影響安裝(請自行測試)(強迫症自己重新授權了)

[root@node1 openssh-8.2p1]# chown root:root -R /root/openssh/openssh-8.2p1

命令行備份原先ssh的配置文件和目錄

然后配置、編譯、安裝

[root@node1 openssh-8.2p1]# chown root:root -R /root/openssh/openssh-8.2p1
[root@node1 openssh-8.2p1]# mv /etc/ssh /etc/ssh.20200521bak   
[root@node1 openssh-8.2p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh/ -with-openssl-includes=/usr/include/openssl --with-ssl-dir=/usr/local/openssl/ --with-zlib --with-md5-passwords --with-pam && make && make install

從原先的解壓的包中拷貝一些文件到目標位置(如果目標目錄存在就覆蓋)

(可能下面的ssh.pam文件都沒用到,因為sshd_config配置文件貌似沒使用它,請自行測試。本人是拷貝了)

[root@node1 openssh-8.2p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@node1 openssh-8.2p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[root@node1 openssh-8.2p1]# chmod +x /etc/init.d/sshd
[root@node1 openssh-8.2p1]# chkconfig --add sshd
[root@node1 openssh-8.2p1]# systemctl enable sshd

 把原先的systemd管理的sshd文件刪除或者移走或者刪除,不移走的話影響我們重啟sshd服務

[root@node1 openssh-8.2p1]# mv /usr/lib/systemd/system/sshd.service /root/

設置sshd服務開機啟動

[root@node1 openssh-8.2p1]# chkconfig sshd on
Note: Forwarding request to 'systemctl enable sshd.socket'.

修改配置文件

vim /etc/ssh/sshd_config

PermitRootLogin yes    #將此配置改成yes

 

接下來測試啟停服務。都正常

[root@node1 openssh-8.2p1]# systemctl restart sshd
[root@node1 openssh-8.2p1]# systemctl status sshd
● sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd; bad; vendor preset: enabled)
   Active: active (running) since Sat 2020-05-23 03:13:21 CST; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 161820 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS)
  Process: 161828 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
 Main PID: 161836 (sshd)
    Tasks: 1
   Memory: 852.0K
   CGroup: /system.slice/sshd.service
           └─161836 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups

May 23 03:13:20 node1 systemd[1]: Starting SYSV: OpenSSH server daemon...
May 23 03:13:21 node1 sshd[161836]: Server listening on 0.0.0.0 port 22.
May 23 03:13:21 node1 sshd[161836]: Server listening on :: port 22.
May 23 03:13:21 node1 sshd[161828]: Starting sshd:[  OK  ]
May 23 03:13:21 node1 systemd[1]: Started SYSV: OpenSSH server daemon.

  

查看ssh版本

[root@node1 openssh-8.2p1]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1g  21 Apr 2020

  

 


免責聲明!

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



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