Linux OpenSSH-升级 9.0
1、下载安装包
Zlib官网:http://www.zlib.net/ 官网下载
OpenSSL官网:https://www.openssl.org/ github https://github.com/openssl/openssl/tags
OpenSSH官网:https://www.openssh.com/ aliyun https://mirrors.aliyun.com/openssh/portable/
2、开启 telnet 服务,临时关闭防火墙 由于一般登录方式为ssh,所以需要安装其他登录方式,比如Telnet服务,防止升级失败
#安装telnet yum install xinetd telnet-server telnet -y #备份文件securetty mv /etc/securetty.bak #配置telnet登录的终端类型,增加一些pts终端 pts=$'pts/0\npts/1\npts/2\npts/3' && echo "$pts" >> /etc/securetty #开启服务 systemctl start telnet.socket service xinetd start #关闭防火墙(或者开启23端口) systemctl stop firewalld.service systemctl disable firewalld.service
3、解压安装包 安装包依赖
#解压软件包 tar -zxvf zlib-1.2.13.tar.gz tar -zxvf openssl-3.1.0-alpha1 tar -zxvf openssh-9.1p1.tar.gz #备份 根据本机实际的文件地址备份 mv /etc/ssh /etc/ssh.bak cp /etc/pam.d/sshd.pam /etc/pam.d/sshd.pam.bak cp /etc/init.d/sshd /etc/init.d/sshd.bak cp /usr/bin/openssl /usr/bin/openssl.bak ##卸载原有的openssh rpm -e --nodeps `rpm -qa | grep openssh` ###安装相关依赖包 yum install vim gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel zlib-devel tcp_wrappers-devel tcp_wrappers;
4、Zlib安装
#进入zlib解压目录 cd /opt/zlib-1.2.13 #编译安装 ./configure --prefix=/usr/local/zlib make && make test && make install # ll /usr/local/zlib ldconfig -v /sbin/ldconfig
5、OpenSSL安装 SSL更新前如果编译目录下有原版本,需删除后编译,防止SSH编译失败!
#进入openssl解压目录 cd /opt/openssl-3.1.0-alpha1 #编译安装 ./config shared zlib --prefix=/usr/local/ssl make clean && make -j 4 && make install #更新函数库 echo "/usr/lcoal/ssl/lib" >> /etc/ld.so.conf ldconfig ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl ln -s /usr/local/ssl/lib64/libssl.so.1.1 /usr/lib64/libssl.so.3 ln -s /usr/local/ssl/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.3 #检查是否升级成功 (如果失败 查看#更新函数库 地址是否正确 ) openssl version -a #编译OpenSSL时报错,Can‘t locate IPC/Cmd.pm in @INC 缺少IPC/Cmd.pm模块 yum install -y perl-CPAN #openssl: error while loading shared libraries: libssl.so.3: cannot open shared obje 根据编译的核对 #ln -s /usr/local/lib/libssl.so.3 /usr/lib/libssl.so.3 #ln -s /usr/local/lib/libcrypto.so.3 /usr/lib/libcrypto.so.3
6、OpenSSH安装
#进入openssh解压目录 cd /opt/openssh-9.1p1 #编译安装 ./configure --prefix=/usr/local/ssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib make -j 4 && make install #查看目录版本 /usr/local/ssh/bin/ssh -V #复制新ssh文件 cp -rf /opt/openssh-9.1p1/contrib/redhat/sshd.init /etc/init.d/sshd cp -rf /opt/openssh-9.1p1/contrib/redhat/sshd.pam /etc/pam.d/sshd.pam cp -rf /opt/openssh-9.1p1/sshd_config /etc/ssh/sshd_config cp -rf /usr/local/ssh/sbin/sshd /usr/sbin/sshd cp -rf /usr/local/ssh/bin/ssh /usr/bin/ssh cp -rf /usr/local/ssh/bin/ssh-keygen /usr/bin/ssh-keygen #开启sshd chmod u+x /etc/init.d/sshd; chkconfig --add sshd ##自启动 chkconfig --list |grep sshd chkconfig sshd on #允许root登录 echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config echo 'Subsystem sftp /usr/local/ssh/libexec/sftp-server' >> /etc/ssh/sshd_config #重启sshd服务 /etc/init.d/sshd restart /etc/init.d/sshd status #查看升级后ssh版本 ssh -V #启动失败 Failed to start OpenSSH Server daemon 根据 sshd -t 检查
7、关闭 telnet 服务
#关闭telnet服务 systemctl stop xinetd.service systemctl stop telnet.socket #卸载telnet服务 yum remove xinetd telnet-server telnet -y #开启防火墙 systemctl start firewalld.service systemctl enable firewalld.service
8、其他
Permissions 0737 for ‘/etc/ssh/ssh_host_rsa_key’ are too open”问题 解决方法:更改报错文件权限 chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_dsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key 升级完openssh后root账号无法登录的问题 解决方法:查下/etc/ssh/sshd_config的配置文件中。UsePAM 这个是否注释了,去掉注释并修改为UsePAM yes