openssh升级到9.7p1 本文介绍centos7的ssh版本升级过程,从openssh7.4p1升级到openssh9.7p1。
因为客户那里扫描出了很多漏洞,需要升级openssh的版本,yum源默认的最高版本只到7.4,所以只能手动升级到较新的版本。
基础环境
1 2 3 4 5 6 7 8 cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) openssl version OpenSSL 1.0.2k-fips 26 Jan 2017 ssh -V OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
准备工作 openssh9.7p1源码包
提前安装相关的依赖项
1 yum -y install gcc gcc-c++ glibc pam-devel zlib-devel openssl-devel pcre-devel net-tools make autoconf pam* zlib*
由于openssh9.7p1要求openssl版本大于等于1.1.1,因此需要升级安装openssl:openssl-1.1.1w源码包
避免升级过程中出现意外,提前准备telnet连接方式
1 2 3 4 5 6 7 8 9 10 yum install xinetd telnet-server -y vim /etc/securetty pts/0 pts/1 pts/2 pts/3 systemctl enable xinetd telnet.socket systemctl start xinetd telnet.socket netstat -lntp|grep 23 tcp6 0 0 :::23 :::* LISTEN 1/systemd
升级openssl
编译安装
1 2 3 4 5 6 7 8 9 10 11 12 tar xf openssl-1.1.12.tar.gz -C /usr/local/ cd /usr/local/openssl-1.1.1w/mkdir /opt/openssl./config --prefix=/opt/openssl make make install
更新lib文件
1 2 3 4 5 6 7 8 9 10 ldd /opt/openssl/bin/openssl echo "/opt/openssl/lib" >> /etc/ld.so.confldconfig -v lld /opt/openssl/bin/openssl /opt/openssl/bin/openssl version
更新bin文件
1 2 3 4 5 6 7 8 which opensslmv /bin/openssl /bin/openssl.old ln -s /opt/openssl/bin/openssl /bin/opensslopenssl version
升级openssh
编译安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 for i in $(rpm -qa | grep openssh);do rpm -e $i --nodeps;done tar zxvf /home/test/openssh9.7p1.tar.gz –C /usr/local cd /usr/local/openssh-9.7p1/./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/opt/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening make make install
修改sshd.init脚本和配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 cp /usr/local/openssh-9.7p1/contrib/redhat/sshd.init /etc/init.d/cat /etc/init.d/sshd.init | grep SSHDsed -i "s/SSHD=\/usr\/sbin\/sshd/SSHD=\/usr\/local\/openssh\/sbin\/sshd/g" /etc/init.d/sshd.init cat /etc/init.d/sshd.init | grep SSHDcat -n /etc/init.d/sshd.init | grep ssh-keygensed -i "s#/usr/bin/ssh-keygen -A#/usr/local/openssh/bin/ssh-keygen -A#g" /etc/init.d/sshd.init cat -n /etc/init.d/sshd.init | grep ssh-keygenecho 'X11Forwarding yes' >> /etc/ssh/sshd_config echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config echo "PermitRootLogin yes" >> /etc/ssh/sshd_config chmod 600 /etc/ssh/*
启动openssh
1 2 3 4 5 6 7 8 9 cp -arp /usr/local/openssh/bin/* /usr/bin//etc/init.d/sshd.init start ssh –V Chmod +x /etc/rc.d/rc.local echo “/etc/init.d/sshd.init start” >> /etc/rc.d/rc.local
后续 因为不是yum升级的,所以systemctl status sshd是找不到unit文件的,可以用/etc/init.d/sshd.init
代替。