1、升級准備
1.1、查看系統版本和ssh版本
cat /etc/*release
ssh -V
1.2、下載軟件包
Openssh下載地址
Openssl下載地址
wget -P /tmp/ https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz wget -P /tmp/ https://ftp.openssl.org/source/openssl-1.1.1i.tar.gz
2、編譯安裝
安裝openssl
[root@my_test tmp]# tar -xzvf openssl-1.1.1i.tar.gz [root@my_test tmp]# cd /tmp/openssl-1.1.1i [root@my_test openssl-1.1.1i]# ./config --prefix=/usr/local/ssl -d shared Operating system: x86_64-whatever-linux2 Configuring OpenSSL version 1.1.1i (0x1010109fL) for linux-x86_64 Using os-specific seed configuration Creating configdata.pm Creating Makefile ********************************************************************** *** *** *** OpenSSL has been successfully configured *** *** *** *** If you encounter a problem while building, please open an *** *** issue on GitHub <https://github.com/openssl/openssl/issues> *** *** and include the output from the following command: *** *** *** *** perl configdata.pm --dump *** *** *** *** (If you are new to OpenSSL, you might want to consult the *** *** 'Troubleshooting' section in the INSTALL file first) *** *** *** ********************************************************************** [root@my_test openssl-1.1.1i]#make&&make install
安裝openssh
[root@localhost ~]# tar -xzvf openssh-8.4p1.tar.gz [root@localhost ~]# cd openssh-8.4p1 [root@my_test openssh-8.4p1]# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl
make出現錯誤
[root@my_test openssh-8.4p1]# make (cd openbsd-compat && make) make[1]: Entering directory `/tmp/openssh-8.4p1/openbsd-compat' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/tmp/openssh-8.4p1/openbsd-compat'
不指定ssl重新編譯成功。其實我們並不需要升級操作系統的openssl。由於API不同,現在還不支持OpenSSL 1.1.1版本
[root@my_test openssh-8.4p1]# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh [root@my_test openssh-8.4p1]# make [root@my_test openssh-8.4p1]# make install [root@test3 openssl-1.1.1h]# echo '/usr/local/ssl/lib' >> /etc/ld.so.conf [root@test3 openssl-1.1.1h]# ldconfig -v
停止原sshd,拷貝sshd的啟動文件
[root@my_test openssh-8.4p1]#systemctl stop sshd.service [root@my_test openssh-8.4p1]#rm -rf /lib/systemd/system/sshd.service [root@my_test openssh-8.4p1]#systemctl daemon-reload [root@my_test openssh-8.4p1]# cp /tmp/openssh-8.4p1/contrib/redhat/sshd.init /etc/init.d/sshd [root@my_test openssh-8.4p1]# ll /etc/init.d/sshd -rwxr-x--- 1 root root 1721 Dec 14 15:49 /etc/init.d/sshd
啟動sshd失敗
[root@my_test openssh-8.4p1]# /etc/init.d/sshd restart Restarting sshd (via systemctl): Warning: sshd.service changed on disk. Run 'systemctl daemon-reload' to reload units. Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details. [FAILED] [root@my_test openssh-8.4p1]# systemctl status sshd.service ● sshd.service - SYSV: OpenSSH server daemon Loaded: loaded (/etc/rc.d/init.d/sshd; bad; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2020-12-14 15:50:09 CST; 11s ago Docs: man:systemd-sysv-generator(8) Process: 27942 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=1/FAILURE) Main PID: 864 (code=exited, status=0/SUCCESS) CGroup: /system.slice/sshd.service ├─ 2147 nginx: worker process ├─ 2148 nginx: worker process ├─ 2149 nginx: worker process ├─ 2150 nginx: worker process ├─ 5978 /home/fastech/hlagent -port=:15380 ├─18513 /usr/local/aegis/aegis_update/AliYunDunUpdate ├─18931 /usr/local/aegis/aegis_client/aegis_00_93/AliYunDun ├─18946 /usr/local/aegis/alihids/AliHids ├─19220 /usr/local/aegis/aegis_quartz/aegis_quartz └─28684 nginx: master process ./nginx Dec 14 15:50:09 my_test sshd[27942]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Dec 14 15:50:09 my_test sshd[27942]: Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open. Dec 14 15:50:09 my_test sshd[27942]: It is required that your private key files are NOT accessible by others. Dec 14 15:50:09 my_test sshd[27942]: This private key will be ignored. Dec 14 15:50:09 my_test sshd[27942]: sshd: no hostkeys available -- exiting. Dec 14 15:50:09 my_test systemd[1]: sshd.service: control process exited, code=exited status=1 Dec 14 15:50:09 my_test sshd[27942]: [FAILED] Dec 14 15:50:09 my_test systemd[1]: Failed to start SYSV: OpenSSH server daemon. Dec 14 15:50:09 my_test systemd[1]: Unit sshd.service entered failed state. Dec 14 15:50:09 my_test systemd[1]: sshd.service failed. Warning: sshd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
根據報錯提示修改/etc/ssh/ssh_host_ed25519_key權限
[root@my_test openssh-8.4p1]# chmod 0600 /etc/ssh/ssh_host_ed25519_key [root@my_test openssh-8.4p1]# /etc/init.d/sshd restart Restarting sshd (via systemctl): Warning: sshd.service changed on disk. Run 'systemctl daemon-reload' to reload units. [ OK ] [root@my_test openssh-8.4p1]# systemctl daemon-reload [root@my_test openssh-8.4p1]# /etc/init.d/sshd restart Restarting sshd (via systemctl): [ OK ] [root@my_test openssh-8.4p1]# 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 Mon 2020-12-14 15:51:32 CST; 8s ago Docs: man:systemd-sysv-generator(8) Process: 28213 ExecStop=/etc/rc.d/init.d/sshd stop (code=exited, status=0/SUCCESS) Process: 28220 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS) Main PID: 28228 (sshd) CGroup: /system.slice/sshd.service ├─ 2147 nginx: worker process ├─ 2148 nginx: worker process ├─ 2149 nginx: worker process ├─ 2150 nginx: worker process ├─ 5978 /home/fastech/hlagent -port=:15380 ├─18513 /usr/local/aegis/aegis_update/AliYunDunUpdate ├─18931 /usr/local/aegis/aegis_client/aegis_00_93/AliYunDun ├─18946 /usr/local/aegis/alihids/AliHids ├─19220 /usr/local/aegis/aegis_quartz/aegis_quartz ├─28228 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups └─28684 nginx: master process ./nginx Dec 14 15:51:32 my_test sshd[28228]: Server listening on 0.0.0.0 port 22. Dec 14 15:51:32 my_test sshd[28220]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Dec 14 15:51:32 my_test sshd[28220]: @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ Dec 14 15:51:32 my_test sshd[28220]: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Dec 14 15:51:32 my_test sshd[28220]: Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open. Dec 14 15:51:32 my_test sshd[28220]: It is required that your private key files are NOT accessible by others. Dec 14 15:51:32 my_test sshd[28220]: This private key will be ignored. Dec 14 15:51:32 my_test sshd[28228]: Server listening on :: port 22. Dec 14 15:51:32 my_test systemd[1]: Started SYSV: OpenSSH server daemon. Dec 14 15:51:32 my_test sshd[28220]: [ OK ] [root@my_test openssh-8.4p1]#
注冊sshd成服務,設置開機啟動
[root@my_test system]# chkconfig --add sshd <-------注冊sshd服務 [root@my_test system]# chkconfig sshd on [root@my_test system]# chkconfig --list sshd Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@my_test system]#systemctl restart sshd
3、為了防止升級失敗,可以在升級之前安裝telnet服務,通過Telnet連接服務器進行升級
[root@my_test ~]#yum install telnet-server -y [root@my_test ~]#systemctl enable telnet.socket [root@my_test ~]#systemctl start telnet.socket [root@my_test ~]# netstat -anp |grep :23 tcp6 0 0 :::23 :::* LISTEN 1/systemd tcp6 0 0 10.158.56.170:23 192.168.10.201:59192 ESTABLISHED 1/systemd
升級完成關閉telnet
[root@my_test ~]#systemctl stop telnet.socket
[root@my_test ~]#systemctl disable telnet.socket