openssh服务是一个基础服务,这个干什么用的不用多说,为了安全(有些安全部门喜欢这个,经常扫一扫漏洞,然后说你的ssh有漏洞),因此,可能需要升级这个服务,话不多说,直接开干。
升级方式为源码编译安装,openssh的强依赖是openssl,而OpenSSL又是一个非常基础的服务,因此,两者都要升级。
openssh下载地址:openssh-portable安装包下载_开源镜像站-阿里云 openssh计划安装的版本是8.6p
OpenSSL下载地址:/source/old/1.1.1/index.html OpenSSL计划安装的版本是1.1.1p
先安装OpenSSL
这个是sshd服务的一个强依赖,需要注意的是,仅仅是安装新版OpenSSL,lib库做一个动态链接,而旧版OpenSSL是不删除的哦。
- yum group install 'Development Tools' -y
- yum install -y zlib-devel openssl-devel pam-devel libselinux-devel zlib-devel gcc-c++ gcc
- mv openssl-1.1.1p.tar.gz /opt/ && cd /opt
- tar zxf openssl-1.1.1p.tar.gz
- cd openssl-1.1.1p
- #开始预编译
- ./config --prefix=/usr/local/openssl
- #看看有么有错误,如果非零,要排错在重新来过,如果是零下一步。
- ###输出如下:
- [root@EULER1 openssl-1.1.1q]# ./config --prefix=/usr/local/openssl
- Operating system: x86_64-whatever-linux2
- Configuring OpenSSL version 1.1.1q (0x1010111fL) 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
*** - *** 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@EULER1 openssl-1.1.1q]# echo $?
-
- echo $?
- #make是正式编译,这一个步骤比较耗费时间,大概十来分钟
- make
- echo $?
- #正式安装
- make install && echo $?
- #添加所缺函数库
- echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
- #检查函数库
- ldd /usr/local/openssl/bin/openssl
- #使之生效
- ldconfig -v
- #备份一哈
- mv /usr/bin/openssl /usr/bin/openssl_old_bak
- #强制链接一哈
- ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
-
测试一哈:
ldd检查一定要这样才表示ssl正常哦
- [root@slave1 openssl-1.1.1p]# ldd /usr/local/openssl/bin/openssl
- linux-vdso.so.1 => (0x00007ffc2b4db000)
- libssl.so.1.1 => /usr/local/openssl/lib/libssl.so.1.1 (0x00007fb11ab4d000)
- libcrypto.so.1.1 => /usr/local/openssl/lib/libcrypto.so.1.1 (0x00007fb11a663000)
- libdl.so.2 => /lib64/libdl.so.2 (0x00007fb11a45f000)
- libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb11a243000)
- libc.so.6 => /lib64/libc.so.6 (0x00007fb119e80000)
- /lib64/ld-linux-x86-64.so.2 (0x00007fb11ade0000)
- [root@master bin]# openssl version -a
- OpenSSL 1.1.1p 21 Jun 2022
- built on: Wed Aug 31 13:09:52 2022 UTC
- platform: linux-x86_64
- options: bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr)
- compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DNDEBUG
- OPENSSLDIR: "/usr/local/openssl/ssl"
- ENGINESDIR: "/usr/local/openssl/lib/engines-1.1"
解释一哈为什么不删除旧版本的OpenSSL:因为,现在仅仅是让一会要安装的ssh能找到这个新安装的OpenSSL就可以了,旧版还是有用处的,并且这个只是强依赖不是服务,没有安全方面的问题。
前面安装OpenSSL已经把编译环境安装好了,因此,直接开始安装就可以了:
- mv openssh-8.6p1.tar.gz /opt && cd /opt
- tar zxf openssh-8.6p1.tar.gz
- cd openssh-8.6p1
- mv /etc/ssh /etc/ssh_bak
- #这里指定了ssl,固定了安装路径,还是预编译,这一步比较耗费时间,大概3分钟
- ./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
- echo $?
- #编译安装,这一步也比较耗费时间。大概3分钟
- make && make install
- echo $?
- #旧版备份
- mv /usr/sbin/sshd /usr/sbin/sshd_bak
- mv /etc/sysconfig/sshd /opt
- mv /usr/lib/systemd/system/sshd.service /opt
- #新版放入环境变量
- cp -arf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
- #彻底删除旧版
- 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
- #新版可执行程序放入环境变量
- cp -arf /usr/local/openssh/bin/* /usr/bin/
- cp -arf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
- #启动脚本
- cp /opt/openssh-8.6p1/contrib/redhat/sshd.init /etc/init.d/sshd
- chmod +x /etc/init.d/sshd
- cp -a /opt/openssh-8.6p1/contrib/redhat/sshd.pam /etc/pam.d/
- systemctl daemon-reload
- service sshd restart
- chkconfig --add sshd
- chkconfig --level 2345 sshd on
- chkconfig --list
查看一哈版本号,完美升级:
- [root@master bin]# ssh -V
- OpenSSH_8.6p1, OpenSSL 1.1.1p 21 Jun 2022
需要说明一哈,这个ssh升级是将原有的旧版完全清除的哦。
此时有一个新的问题出现了,比如,我升级的这个服务器主机名称是master,IP地址是192.168.217.16,在另一个主机名称为slave1,IP地址是192.168.217.17的服务器上ssh连接master,报错了:
- [root@slave1 ~]# ssh master
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- @ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- The ECDSA host key for master has changed,
- and the key for the corresponding IP address 192.168.217.16
- is unchanged. This could either mean that
- DNS SPOOFING is happening or the IP address for the host
- and its host key have changed at the same time.
- Offending key for IP in /root/.ssh/known_hosts:7
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
- Someone could be eavesdropping on you right now (man-in-the-middle attack)!
- It is also possible that a host key has just been changed.
- The fingerprint for the ECDSA key sent by the remote host is
- SHA256:mPvQ5bgLEFPP0OMZFFJK7Sq+zgzXmm/63vWDTur9QWY.
- Please contact your system administrator.
- Add correct host key in /root/.ssh/known_hosts to get rid of this message.
- Offending ECDSA key in /root/.ssh/known_hosts:4
- ECDSA host key for master has changed and you have requested strict checking.
- Host key verification failed.
这么一大串并没什么,说了很多,总结一句话就是原来有做免密,现在因为sshd升级了,需要更新一哈原来的密钥,怎么更新呢?
在slave1这个服务器上执行清除密钥命令就可以了:
- [root@slave1 ~]# ssh-keygen -R master
- # Host master found: line 4
- /root/.ssh/known_hosts updated.
- Original contents retained as /root/.ssh/known_hosts.old
现在在ssh连接就没太多的问题了:
- [root@slave1 ~]# ssh master
- The authenticity of host 'master (192.168.217.16)' can't be established.
- ECDSA key fingerprint is SHA256:mPvQ5bgLEFPP0OMZFFJK7Sq+zgzXmm/63vWDTur9QWY.
- ECDSA key fingerprint is MD5:67:b8:a0:bf:44:b1:28:d4:16:59:7b:8a:e3:9e:77:43.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added 'master' (ECDSA) to the list of known hosts.
- Last login: Wed Aug 31 18:57:17 2022 from 192.168.217.1
最后多说一句,如果需要root用户能够登录ssh,那么,需要在配置文件中开启:
- echo "PermitRootLogin yes">>/etc/ssh/sshd_config
- service sshd restart
scp 等等相关命令也是可以正常使用的,本次升级opessh成功啦。
可能会出现的问题:
xshell5连接原服务器报错,如下图
这个时候就不用太犟了,xshell一般升级到6或者7都可以解决的,必须升级。