更新软件包
yum update -y
安装编译环境
yum install zlib.x86_64 zlib-devel.x86_64 gcc wget pam-devel -y
升级openssl
查看openssl版本
openssl version -a
下载新版本
cd /usr/local/src/
wget https://www.openssl.org/source/openssl-3.3.0.tar.gz
tar -zxvf openssl-3.3.0.tar.gz
cd openssl-3.3.0
备份旧版本文件
mv /usr/bin/openssl /usr/bin/openssl.old
安装IPC/Cmd.pm 模块
#安装perl-CPAN
yum install perl-CPAN -y
#进入perl shell中
perl -MCPAN -e shell
第一步选yes
第二步选manual
第三步选yes
#在出现出现cpan[1]>安装缺少的模块
install IPC/Cmd.pm
注:最后一步安装会有点慢,耐心等待即可
exit
退出进入perl shell
编译安装新版本
#配置安装环境
./config --prefix=/usr/local/openssl
#编译
make
#安装
make install
#替换原有旧openssl文件
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib64/libssl.so.3 /usr/lib64/libssl.so.3
ln -s /usr/local/openssl/lib64/libcrypto.so.3 /usr/lib64/libcrypto.so.3
#在/etc/ld.so.conf文件中写入openssl库文件的搜索路径
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
#使修改后的/etc/ld.so.conf生效
ldconfig
#验证版本
openssl version -a
升级openssh
安装telnet防止ssh失败无法登录
#安装telnet服务和xinetd守护进程
yum install telnet-server.x86_64 xinetd -y
#配置开机启动
systemctl enable xinetd.service
systemctl enable telnet.socket
#启动服务
systemctl start telnet.socket
systemctl start xinetd
#开启防火墙允许访问23端口
firewall-cmd --add-port=23/tcp --permanent
firewall-cmd --reload
#默认root无法远程访问,修改/etc/securetty
vi /etc/securetty
在末尾添加
pts/0
pts/1
pts/2
#检查23端口是否可以登录
下载新版本
cd /usr/local/src/
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.7p1.tar.gz
tar -zxvf openssh-9.7p1.tar.gz
cd openssh-9.7p1
编译安装新版本
#配置安装环境
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/lib64 --without-hardening
#编译
make
#安装
make install
修改配置文件
vi /etc/ssh/sshd_config
PermitRootLogin yes
UseDNS no
UsePAM no
配置服务
#复制文件到系统服务目录
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
#添加执行权限
chmod +x /etc/init.d/sshd
#添加服务,配置开机启动
chkconfig --add sshd
systemctl enable sshd
chkconfig sshd on
#原来的服务移走,否走有时重启后ssh服务起不来
mv /usr/lib/systemd/system/sshd.service /home/
##确保文件权限正确,通常它们应该有权限600(只有所有者有读写权限)
chmod 600 /etc/ssh/ssh_host_*_key
##重新加载
systemctl daemon-reload
重启服务
/etc/init.d/sshd restart
关闭telnet
systemctl disable xinetd.service
systemctl stop xinetd.service
systemctl disable telnet.socket
systemctl stop telnet.socket
验证升级是否成功
ssh -V