Linux OpenSSH升级
升级openssh之前需要先升级openssl
1、升级准备##1.1、查看系统版本和ssh版本
linux 系统版本
cat /etc/redhat-release
# 或者
uname -a
openssh 查看一下原安装版本
ssh -V
openssl 查看一下原安装版本
openssl version
1.2、下载软件包
Openssh下载地址
Openssl下载地址
https://www.openssl.org/source
2. 开始安装
2.1 安装环境依赖
2.1.1 更新yum镜像
注意: 如果centos8中没有安装wget,需要先执行 yum install wget -y 接下来完成如下操作: 进入到yum.repos.d目录下:cd /etc/yum.repos.d
查看linux系统版本
cat /etc/redhat-release
备份(拷贝)CentOS-Base.repo文件:mv CentOS-Base.repo CentOS-Base.repo.bak
按需下载, 下载centos8阿里镜像源:wget -O /etc/yum.repos.d/CenOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
更新镜像:yum clean all
生成缓存:yum makecache
-------------------------------------------------------------------------------------------------------------------------------
2. 1. 2 首先, 安装telnet工具。(为了避免在升级的过程中断开)
#1.telnet安装
yum install -y telnet telnet-server xinetd
#2.启动telnet服务
systemctl start xinetd && systemctl start telnet.socket
#3.开放防火墙23端口
firewall-cmd --zone=public --add-port=23/tcp --permanent
#4.重新加载防火墙规则
firewall-cmd --complete-reload
#5.查询23端口放行情况
firewall-cmd --query-port=23/tcp
#6.开放telnet明文登录
sed -i 's/^auth[[:space:]]\+required[[:space:]]\+pam_securetty.so/#&/' /etc/pam.d/remote
#7.测试telnet登录
telnet ip
#8.加入开机启动
systemctl enable telnet.socket
切换到telnet方式登录,以后的操作都在telnet终端下操作,防止ssh连接意外中断造成升级失败
telnet方式登录
-------------------------------------------------------------------------------------------------------------------------------
1)安装gcc(编译依赖 gcc 环境)
yum install gcc-c++
2)安装 PCRE pcre-devel (包括 perl 兼容的正则表达式库)
yum install -y pcre pcre-devel
3)安装zlib(对 http 包的内容进行 gzip)
yum install -y zlib zlib-devel
4)安装perl-IPC-Cmd
yum -y install perl-IPC-Cmd
yum install -y perl-CPAN
或者
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pam-devel pam-devel pore-devel
yum install -y pam* zlib*
yum -y install perl-IPC-Cmd
yum install -y perl-CPAN
-------------------------------------------------------------------------------------------------------------------------------
2.2 开始安装openssl
-------------------------------------------------------------------------------------------------------------------------------
2.2.1将下载好的压缩包放到/usr/local/路径下(根据自己实际需求定义)
cd /usr/local/
#压缩包解压 : tar -zxvf openssl-3.3.1.tar.gz
# 切换到解压后的路劲
cd /usr/local/openssl-3.3.1/
mkdir /usr/local/openssl #可以不执行
# 设置配置
./config --prefix=/usr/local/openssl -d shared
# 编译安装
make && make install
# 这个命令会比较久
备份原始文件
mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/lib64/openssl /usr/lib64/openssl.old mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl ln -sf /usr/local/openssl/include/openssl /usr/include/openssl ln -sf /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so echo "/usr/local/openssl/lib64" >> /etc/ld.so.conf
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v
升级后版本
[root@zabbix ~]# openssl version OpenSSL openssl-3.3.1 xx XXX xxxx
-------------------------------------------------------------------------------------------------------------------------------
2.3 安装openssh,下载好的压缩文件放在 /usr/local 下面
- # 卸载旧版本
- service sshd stop
- rpm -e `rpm -qa| grep openssh` --nodeps
- cp -r /etc/ssh/ /etc/ssh_bak
- rm -rf /etc/ssh/*
- #1.卸载openssh7.4p1
- yum remove -y openssh
- #2.清理残余文件
- rm -rf /etc/ssh/*
----------------------------------
# 开始安装
cd /usr/local tar -xzvf openssh-9.8p1.tar.gz
chown -R root.root openssh-9.8p1
cd openssh-9.8p1
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --without-openssl-header-check --with-pam --with-privsep-path=/var/lib/sshd --with-md5-passwords --with-zlib=/usr/local/src/zlib
-------------------------------------------------------------------------------------
# 编译
make -j 4 && make install
----------------------------------------------------------------------------------------------
#4.查看目录版本 /usr/local/openssh/bin/ssh -V
# 复制启动文件到/etc/init.d/下并命名为sshd
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
#6.允许root登录
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
#重启sshd服务
/etc/init.d/sshd restart
#查看服务运行状态
/etc/init.d/sshd status
#添加开机启动
chkconfig --add sshd
#查看升级后ssh版本
ssh -V
## 报错1
------------------------------------------------------------------------------------- #报错 # configure: error: *** zlib.h missing – please install first or check config.log 下载最新的zlib,放到/usr/local/src并解压,执行下面代码(下载地址: https://www.zlib.net/) cd /usr/local tar zxf zlib.tar.gz cd zlib-1.3.1 ./configure --with-zlib=/usr/local/src/zlib-1.2.11 ./configure make test make install make clean ./configure --shared make test make install cp zutil.h /usr/local/include/ cp zutil.c /usr/local/include/
报错2:
---------------------------------------------------------------------------------------------- # 报错(参考链接: https://www.cnblogs.com/wholj/p/10897274.html) Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. sshd: no hostkeys available -- exiting. 解决办法 在执行完make install命令后可能就会有关于key文件的警告信息,这个时候需要将涉及到的key文件的权限改成600,如果没修改,则重启sshd服务时将报错。 chmod 600 /etc/ssh/ssh_host_rsa_key chmod 600 /etc/ssh/ssh_host_ecdsa_key chmod 600 /etc/ssh/ssh_host_ed25519_key
标签:--,openssh,openssl,etc,usr,centos8,local,ssh From: https://www.cnblogs.com/procedureMonkey/p/18290881