赞
踩
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
提示:升级原因及项目环境:
升级原因:政企项目所属国产服务器下,需要使用openSSH方能远程连接服务器,在一次等保测评的时候由于openSSH版本过低扫描出远程服务存在安全隐患的漏洞,需要对openSSH进行远程升级操作。
项目环境:
# 查询操作系统
lsb_release -a
1、服务器操作系统:UnionTech OS Server 20(基于国产开源Deepin系统开发,Deepin系统基于大型社区开源系统Debian系统开发,所以与Ubuntu系统类似,本次升级方案也适用于Ubuntu)
2、版本更新:openSSH8.3p1 -> openSSH9.1p1
提示:以下是本篇文章正文内容,下面案例可供参考
OpenSSH和OpenSSL是两个常用的开源软件包,用于提供安全的网络通信和加密功能。
OpenSSH是一个用于安全登录和远程 shell 会话的工具集,基于SSH(Secure Shell)协议。它能够加密所有的网络通信,包括密码、文件和远程命令等。OpenSSH还提供了 SFTP(SSH File Transfer Protocol)和SCP(Secure Copy Protocol)等文件传输协议,使文件传输也能够进行安全加密。
OpenSSL是一个开源的加密工具包,提供了一系列密码学功能,包括对称加密、非对称加密、数字签名、密钥交换等。OpenSSL还提供了 SSL/TLS 协议的实现,用于在网络通信中建立安全的连接。它可以用于开发安全的网络应用程序,如网站服务器、邮件服务器、VPN 等。
OpenSSH和OpenSSL在许多操作系统中都有广泛的应用。它们具有安全、可靠、稳定的特性,并且经过了长时间的发展和优化,被广泛认可并广泛使用。
注意:如果确保你的网络是没问题的,那这步骤可以跳过openssh以及openssl的资源链接:
vim /etc/apt/sources.list 添加如下镜像地址:
#debian 9.x (stretch) 阿里云镜像仓库 deb https://mirrors.aliyun.com/debian-archive/debian stretch main contrib non-free #deb https://mirrors.aliyun.com/debian-archive/debian stretch-proposed-updates main non-free contrib deb https://mirrors.aliyun.com/debian-archive/debian stretch-backports main non-free contrib deb https://mirrors.aliyun.com/debian-archive/debian-security stretch/updates main contrib non-free deb-src https://mirrors.aliyun.com/debian-archive/debian stretch main contrib non-free #deb-src https://mirrors.aliyun.com/debian-archive/debian stretch-proposed-updates main contrib non-free deb-src https://mirrors.aliyun.com/debian-archive/debian stretch-backports main contrib non-free deb-src https://mirrors.aliyun.com/debian-archive/debian-security stretch/updates main contrib non-free 或清华源 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse Ubuntu由于没有公钥,无法验证下列签名。 公钥就是:3B4FE6ACC0B21F32(实际看自己的是什么) 输入以下命令: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 公钥 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 更新apt apt update
1、打开终端并以 root 用户登录,正式开始安装openssl和openssh,以下步骤如果出现权限问题需要用sudo
2、由于远程升级openSSH存在断连的风险,所以为了避免升级时openSSH无法使用需要先安装另外一个远程控制与管理的服务,安装telnet:
// 1、安装openbsd-inetd和telnetd,如果已经安装过了,会提示已经安装过了,直接执行下面的步骤就可以了。 apt-get install openbsd-inetd telnetd telnet // 离线上传安装包需要解压 dpkg -i telnet_0.17-41_arm64.deb dpkg -i openbsd-inetd_0.20221205-1_arm64.deb // 安装完之后,查看inetd.conf ####cat /etc/inetd.conf | grep telnet 输出: telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd // 2、重启服务 ####/etc/init.d/openbsd-inetd restart // 3、查看服务状态 /etc/init.d/openbsd-inetd status // 4、查看telnet服务的默认端口是否启动 netstat -anpt|grep 23 // 5、测试是否成功登陆 telnet 127.0.0.1 // 6、停止服务(openSSH升级重启后,需要停止telnet并卸载) /etc/init.d/openbsd-inetd stop systemctl stop openbsd-inetd // 7、卸载该服务的安装 apt-get remove openbsd-inetd apt-get remove telnetd // 或卸载软件包(配置文件一起删除) dpkg -P openbsd-inetd dpkg -P telnetd // 8、查询服务是否卸载完全 dpkg -l | grep telnetd dpkg -l | grep openbsd-inetd // 9、删除该服务的配置文件 dpkg --purge telnetd dpkg --purge openbsd-inetd
代码如下(示例):
// 2、安装 libpam0g-dev(已安装请忽略,重点强调:ubuntu下是安装libpam0g-dev ,不装下面安装会报错PAM headers not found) apt-get install libpam0g-dev // 或者离线上传安装包需要解压 dpkg -i libpam0g-dev_1.5.2-6_arm64.deb // 1、下载源代码存档(无法访问,则去官网下载安装包上传到服务器) wget https://www.zlib.net/zlib-1.2.13.tar.gz // 2、解压下载的安装包 tar -xvf zlib-1.2.13.tar.gz // 3、进入文件夹zlib cd zlib-1.2.13 // 4、修改配置 ./configure --prefix=/usr/local/zlib // 5、安装 make && make install // 6、备份原来的openssl mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl /usr/include/openssl.bak // 7、从下载的包中提取文件(去官网下载安装包上传到服务器) tar -xvf openssl-1.0.2o.tar.gz // 8、进入文件夹openssl cd openssl-1.0.2o // 9、修改配置(一定要加上shared 参数,要不在安装openssh的时候就无法找到,最好指定安装路径,不然找不到安装好的openssl在哪) ./config --prefix=/usr/local/openssl shared zlib // 10、安装 make && make install // 11、因为源码安装默认安装的位置是 /usr/local/ssl 需要将创建软链接到系统位置 ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl ln -s /usr/local/ssl/include/openssl /usr/include/openssl // 12、将openssl 的lib 库添加到系统(如果echo不行,可以直接使用vim添加) echo "/usr/local/ssl/lib" > /etc/ld.so.conf.d/openssl.conf // 13、使新添加的lib 被系统找到 ldconfig // 14、查看openssl版本(如果能正常显示openssl最新的版本,证明安装成功) openssl version -a
// 1、备份原openssh文件 mv /etc/init.d/ssh /etc/init.d/ssh.old cp -r /etc/ssh /etc/ssh.old // 2、卸载原openssh apt-get remove openssh-server openssh-client // 3、安装 libpam0g-dev(已安装请忽略,重点强调:ubuntu下是安装libpam0g-dev ,不装下面安装会报错PAM headers not found) apt-get install libpam0g-dev // 执行./configure报错:checking whether the c compiler works... no apt-get install build-essential // 执行./configure报错:zlib没有安装 apt-get install zlib1g-dev // 或者离线上传安装包需要解压 dpkg -i libpam0g-dev_1.5.2-6_arm64.deb // 4、从下载的包中提取文件(去官网下载安装包上传到服务器) tar xf openssh-9.1p1.tar.gz // 5、进入文件夹openssh cd openssh-9.1p1 // 6、修改配置(需要指定openssl的安装路径) #####./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-ssl-dir=/usr/local/ssl --with-privsep-path=/var/lib/sshd // 7、安装(重点:如果这个config过程中报错configure: error: PAM headers not found,说明一开始的pam依赖没装好) make && make install // 8、可查看当前SSH的版本,到目前所有升级就已经完成了 ssh -V // 9、下面进行还原ssh配置 cd /etc/ssh // 10.还原sshd_config mv sshd_config sshd_config.default ####cp ../ssh.old/sshd_config ./ // 11、使用原来的/etc/init.d/ssh mv /etc/init.d/ssh.old /etc/init.d/ssh // (9.1版本内置了sftp)修改/etc/ssh/sshd_config文件,注释掉 #Subsystem sftp /usr/lib/openssh/sftp-server 添加字段 Subsystem sftp internal-sftp // 查找sshd_config配置文件报错 /usr/sbin/sshd -T // 如 line 89 Bad configuration option: StrictHostKeyChecking line 91 Bad configuration option: UserKnownHostsFile // 然后执行,修改对应行,这里去掉就行了,根据正常的sshd_config来改 sudo vi /etc/ssh/sshd_config // 12、取消注销指定服务 systemctl unmask ssh // 13、重启服务 systemctl restart sshd // 14、查看服务 systemctl status sshd // 14、停止服务 systemctl stop sshd
/etc/ssh/ssh_config line 55: Unsupported option “gssapiauthentication”
/etc/ssh/ssh_config line 56: Unsupported option “gssapidelegatecredentials”
解决办法:修改/etc/ssh/ssh_config 注释掉这两个地方
Unable to negotiate with xxx.xx.xxx.xx port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
解决办法:
vim ~/.ssh/config,有就修改,没有就新增
添加一行:
HostKeyAlgorithms +ssh-dss
然后重启sshd: service sshd restart
如果出现这类问题 :直接删除掉~/.ssh/known_hosts文件,或者备份改名就可以ssh了
systemctl status ssh
查看ssh运行状态时,有报错
pam_deepin_authentication(sshd:auth): Failed to call ‘FindUserByName’: com.deepin.DBus.Error.Unnamed>
解决办法:
systemctl restart dbus
dpkg: 处理软件包 libc6:arm64 (–configure)时出错
已安装 libc6:arm64软件包 post-installation 脚本 子进程返回错误状态 1
在处理时有错误发生
libc6:arm64
E: Sub-process /usr/bin/dpkg returned an error code (1)
执行如下命令
cd /var/lib/dpkg
sudo mv info info.baksudo
sudo mkdir info
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了统信UOS下升级openssh及openssl,更多情况还请查阅其他文献。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。