由于安全漏洞扫描显示OpenSSH版本过低需升级至最新版,故编写该文档。
本文转载自link于2021-06-30由宇宙最帅的男人发布
[root@localhost ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
实测中,我的Centos版本是7.2-1511,同样成功
[root@localhost ~]# yum -y install wget gcc zlib-devel openssl-devel pam-devel libselinux-devel
[root@localhost ~]# mv /usr/bin/openssl{,.bak}
[root@localhost ~]# mv /usr/include/openssl{,.bak}
[root@localhost ~]# wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
[root@localhost ~]# tar zxf openssl-1.1.1k.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/openssl-1.1.1k/
[root@localhost openssl-1.1.1k]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.1.1k]# make -j 2 && make install
[root@localhost openssl-1.1.1k]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.1.1k]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
[root@localhost openssl-1.1.1k]# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1k]# ldconfig -v
[root@localhost openssl-1.1.1k]# openssl version
OpenSSL 1.1.1k 25 Mar 2021
[root@localhost ~]# systemctl stop sshd
[root@localhost ~]# mv /etc/ssh{,.bak}
[root@localhost ~]# mv /etc/pam.d/sshd{,.bak}
[root@localhost ~]# rpm -e --nodeps `rpm -qa | grep openssh`
[root@localhost ~]# wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
[root@localhost ~]# tar zxf openssh-8.6p1.tar.gz
[root@localhost ~]# cd openssh-8.6p1
[root@localhost openssh-8.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --without-hardening
[root@localhost openssh-8.6p1]# make -j 2 && make install
[root@localhost openssh-8.6p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.6p1]# mv /etc/pam.d/sshd.bak /etc/pam.d/sshd
[root@localhost openssh-8.6p1]# mv /etc/ssh /etc/ssh_update.bak
[root@localhost openssh-8.6p1]# mv /etc/ssh.bak /etc/ssh
[root@localhost openssh-8.6p1]# chmod 600 /etc/ssh/*key
[root@localhost openssh-8.6p1]# chkconfig --add sshd
[root@localhost openssh-8.6p1]# chkconfig sshd on
[root@localhost openssh-8.6p1]# systemctl restart sshd
[root@localhost ~]# sed -i 's/^#\(PermitRootLogin \).*/\1yes/' /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1k 25 Mar 2021
我的验证
ssh-V、sshd-V、openssl version、systemctl status sshd.service等各项验证
第三方工具验证 OK
别的服务器SSH到测试机
原因:是因为ssh升级过后,服务器的公钥信息改变了,所以导致无法连接的。
用OpenSSH的人都知ssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts。
当下次访问相同计算机时,OpenSSH会核对公钥。如果公钥不同,OpenSSH会发出警告,如果我们重新安装系统,其公钥信息还在,连接会出现如上图所示
解决方法:
rm -rf ~/.ssh/known_hosts 优点:干净利索 / 缺点:把其他正确的公钥信息也删除,下次链接要全部重新经过认证
vi ~/.ssh/known_hosts 删除对应ip的相关rsa信息优点:其他正确的公钥信息保留 / 缺点:还要vi,还要找到对应信息,稍微优点繁琐
ssh-keygen -R 172.16.5.251清除旧的公钥信息优点:快、稳、狠 / 缺点:没有缺点
我升级过程没有遇到此问题,测试机重启过没有遇到,一切正常
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
grep sshd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp