Ubutu18.04.5版本openssh升级到8.4及open file文件更改

ubuntu18.04.5版本OpenSSH是7.6p1。存在好多漏洞,需要对opnessh进行升级,升级会对openfile有影响,按照本文操作升级完openssh后,openfile依然可以使用。

选择源码进行升级,需要准备一下安装包:
1.zlib压缩库提供的内存中的压缩和解压功能,包括未压缩数据的完整性检查。
zlib-1.2.11.tar.gz 官方下载地址: http://www.zlib.net/

2.OpenSSH是用于使用SSH协议进行远程登录的主要连接工具。它对所有流量进行加密,以消除窃听,连接劫持和其他攻击.
openssh-8.4p1 官网下载地址:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

在安装之前需要先进行库升级,使用的源是官方源:

apt-get update
apt-get upgrade

需要安装的软件包:

apt-get install libpam0g-dev

解压zlib压缩包:

tar xf zlib-1.2.11.tar.gz

进入到解压后的目录下:

cd zlib-1.2.11

进行编译安装:

/zlib-1.2.11# ./configure --prefix=/usr/local/zlib

系统产生了报错:

Checking for gcc...
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.

需要将configure文件里的394行进行注释掉:

 #echo "Checking for obsessive-compulsive compiler options..." >> configure.log
 #if try $CC -c $CFLAGS $test.c; then
 #  :
 #else
 #  echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log
 #  leave 1
 #fi
 :wq!

继续操作报错:

Checking for gcc...
Checking for shared library support...
No shared library support.
Building static library libz.a version 1.2.11 with cc.
Checking for size_t... No.
Checking for long long... No.
Failed to find a pointer-size integer type.
** ./configure aborting.

查找是因为缺少l解压文件:

apt-get install build-essential

继续操作:

make&make install
cp zutil.h /usr/local/include
cp zutil.c /usr/local/include

3.升级openssh:
备份文件:

mv /etc/init.d/ssh /etc/init.d/ssh.bak
cp -r /etc/ssh /etc/ssh.bak
mv /etc/pam.d/sshd /etc/pam.d/sshd.bak

在卸载前物理机建议先安装telnet以免升级失败
卸载openssh:

apt-get remove -y openssh-server openssh-client

解压openssh8.4p1压缩文件:

 tar -xf openssh-8.4p1.tar.gz

进去到解压后的目录下:

cd openssh-8.4p1/

进行安装:

./configure  --prefix=/usr  --sysconfdir=/etc/ssh  --with-pam

出现报错:

configure: error: *** zlib.h missing - please install first or check config.log ***

缺少zlib-dev包,需要安装zlib1g.dev包:

apt-get install zlib1g.dev

又出现报错:

configure: error: *** working libcrypto not found, check config.log

缺少libssl-dev包,需要安装libssl-dev包:

apt-get install libssl-dev

继续升级:

make&make install

还原文件:

cd /etc/ssh
mv sshd_config sshd_config.default
cp ../ssh.bak/sshd_config ./
mv /etc/init.d/ssh.bak /etc/init.d/ssh
mv /etc/pam.d/sshd.bak /etc/pam.d/sshd

取消unmask值:

systemctl unmask sshd

重启ssh服务:

systemctl restart sshd

4.修改open file参数:
在vim /etc/security/limits.conf配置文件里添加:

* soft nofile 65535
* hard nofile 65535
:wq!

版权声明:本文为colo_w原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。