如何在Ubuntu中将OpenSSL从1.0.2g升级到1.1.0g并使Python识别新的OpenSSL。

14

我使用的操作系统是Ubuntu 16.04,其所含的OpenSSL版本为1.0.2g。我需要使用1.1.0g版本的OpenSSL。注意,我的另一台机器上的Ubuntu 18已安装了此版本的OpenSSL。但我需要在Ubuntu 16.04上运行一个Python程序,因此需要特定的1.1.0g版本。我尝试了以下操作:

sudo apt-get upgrade
sudo apt-get update

但是在我的Ubuntu机器上,OpenSSL没有更新。我该怎么更新呢?

我使用python socket、ssl模块在443端口上建立TLS连接。如果我将旧版的OpenSSL 1.0.2g更新为OpenSSL 1.1.0g,那么python是否会自动识别OpenSSL 1.1.0g

升级OpenSSL的原因是我需要运行python程序ssl socket,但是需要使用OpenSSL 1.1.0g

当我尝试时:

sudo apt-get install openssl

通过以下命令检查OpenSSL版本:openssl version -a,发现旧版本为OpenSSL 1.0.2g

请问如何在Ubuntu 14.06机器上获取新版本的OpenSSL 1.1.0g

2个回答

29

为什么你无法通过更新来在Ubuntu 16.04上使用OpenSSL 1.1.0g:

你的Ubuntu 18有OpenSSL 1.1.0g,因为该版本可用于其软件包库。有时,软件包可能存在多个版本。但是,看起来Ubuntu 16.04根本没有您需要的版本可用。这就是为什么您不能通过更新来在Ubuntu 16.04上使用OpenSSL 1.1.0g的原因。

可以在软件包库中找到的版本与不同

如何安装:

您需要手动安装它或者找到一个适用于Ubuntu 16.04的软件包库,使其可用于系统。我不确定是否有可用的软件包库,因此,如果您想手动安装,请按照以下步骤操作:

wget https://www.openssl.org/source/old/1.1.0/openssl-1.1.0g.tar.gz
tar xzvf openssl-1.1.0g.tar.gz
cd openssl-1.1.0g
./config
make
sudo make install

openssl version -a

就是这样了!

警告:通过安装一个不在系统中默认可用的新版本 OpenSSL,您引入了一个与系统维护提供的更新不兼容的版本。您需要自行处理。也许根据您的情况,最好只使用默认具有所需 OpenSSL 版本的 Ubuntu 18。 这是最简单和最安全的方式。

希望一切顺利。 祝你好运!


1
非常感谢你抽出时间回答我的问题。我确实按照你提到的步骤从仓库中安装了它。安装看起来很成功。但是,当我再次检查版本时,显示的仍然是旧版本。我放弃了OpenSSL并格式化了我的设备为Ubuntu 18。 - user9371654
1
谢谢,它起作用了!不过显然最好的建议是升级到Ubuntu 18。 - user2677034
7
谢谢Edson。顺便说一下,在完成所有的制作/安装后,如果您像我在Ubuntu 16.04.6 x86_64上看到这个消息:openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory``` 那么请使用ldconfig或直接输入此行: `export LD_LIBRARY_PATH=/usr/local/lib/` - ywu
1
非常感谢您的贡献,@ywu。欢迎您随时再来。 - edson.a.soares
@AndrewHenle 你说得基本正确,但在我的情况下,我正在处理一个没有接收到操作系统更新的系统,所以这没什么。那个系统非常不幸。 - Peter Dowdy
显示剩余3条评论

3

以下是我如何从源代码安装最新版本的openssl。

# Install make and packages required to compile the source code
apt-get install -y libfindbin-libs-perl build-essential

# Download source code
wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1k.tar.gz -O openssl.tar.gz

# Extract source code
tar -xf openssl.tar.gz

# Go to the source code folder
cd openssl-OpenSSL_1_1_1k

# Configure to compile it
./config --libdir=/usr/local/lib

# Compile with 4 parelel jobs
make -j 4

# Install compiled code
sudo make install

# Move older executable
sudo mv /usr/bin/openssl /usr/bin/openssl-1.0.2g

# Create soft symbolic link to the newer version of openssl
sudo ln -s /usr/local/bin/openssl /usr/bin/openssl

# Make visible the new libraries installed at /usr/local/lib
sudo ldconfig

ln -s /usr/local/bin/openssl /usr/bin/openssl?!?!? 天哪 不要这样做!!! 永远不要动操作系统提供的二进制文件。你认为下次更新操作系统时,如果 openssl 二进制文件是其中一部分,会发生什么? - Andrew Henle
我按照它的步骤操作了,但是nginx内置的OpenSSL版本并没有改变。那该怎么办呢? - jayaprakash R

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接