簡體   English   中英

如何在 Ubuntu 上安裝 OpenSSL 庫?

[英]How do I install the OpenSSL libraries on Ubuntu?

我正在嘗試在使用 OpenSSL 1.0.0 的 Ubuntu 10.04 LTS 上構建一些代碼。 當我運行 make 時,它​​會使用“-lssl”選項調用 g++。 來源包括:

#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/des.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>

我跑了:

$ sudo apt-get install openssl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openssl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

但我猜 openssl 包不包含庫。 我在 make 上遇到這些錯誤:

foo.cpp:21:25: error: openssl/bio.h: No such file or directory
foo.cpp:22:28: error: openssl/buffer.h: No such file or directory
foo.cpp:23:25: error: openssl/des.h: No such file or directory
foo.cpp:24:25: error: openssl/evp.h: No such file or directory
foo.cpp:25:25: error: openssl/pem.h: No such file or directory
foo.cpp:26:25: error: openssl/rsa.h: No such file or directory

如何在 Ubuntu 10.04 LTS 上安裝 OpenSSL C++ 庫?

我為 -l 選項做了一個man g++和(在“鏈接選項”下)它指出:“鏈接器搜索庫的標准目錄列表......”和“搜索的目錄包括幾個標准系統目錄.. .”那些標准的系統目錄是什么?

你要安裝開發包,也就是libssl-dev:

sudo apt-get install libssl-dev

跑:

apt-get install libssl-dev

我怎么能自己弄清楚(除了在這里問這個問題)? 我可以以某種方式告訴 apt-get 列出所有包,並告訴 ssl 的 grep 嗎? 還是我需要知道“lib*-dev”命名約定?

如果您使用-lfoo鏈接,那么該庫可能是libfoo.so 庫本身可能是libfoo包的一部分,而頭文件在您發現的libfoo-dev包中。

有些人使用 GUI“突觸”應用程序 ( sudo synaptic ) 來(定位和)安裝包,但我更喜歡使用命令行。 更容易從命令行找到正確包的一件事是apt-get支持 bash 補全。

嘗試輸入sudo apt-get install libssl然后點擊tab查看匹配包名稱的列表(當您需要選擇具有多個版本或其他變體的包的正確版本時,這會有所幫助)。

Bash 補全實際上非常有用……例如,您還可以通過鍵入sudo apt-get然后點擊tabapt-get支持的命令列表。

我在這里找到了一個詳細的解決方案: 在 Linux 上手動安裝 OpenSSL

從博客文章...:

下載、編譯、安裝步驟如下(以下我安裝的是1.0.1g版本,請將“1.0.1g”替換為你的版本號):

步驟 – 1:下載 OpenSSL:

運行命令如下:

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz

此外,下載 MD5 哈希以驗證下載文件的完整性,僅用於變異目的。 在您從網站下載 OpenSSL 文件的同一文件夾中:

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz.md5
$ md5sum openssl-1.0.1g.tar.gz
$ cat openssl-1.0.1g.tar.gz.md5

步驟 – 2:從下載的包中提取文件:

$ tar -xvzf openssl-1.0.1g.tar.gz

現在,進入解壓包的目錄,比如openssl-1.0.1g

$ cd openssl-1.0.1g

第 3 步:配置 OpenSSL

使用可選條件運行以下命令以設置要復制文件和文件夾的前綴和目錄。

$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl

您可以將“/usr/local/openssl”替換為要復制文件和文件夾的目錄路徑。 但請確保在執行此步驟時檢查終端上是否有任何錯誤消息。

第 4 步:編譯 OpenSSL

要編譯 openssl,您需要運行 2 個命令:make, make install 如下:

$ make

注意:檢查任何錯誤消息以進行驗證。

步驟-5:安裝OpenSSL:

$ sudo make install

或者沒有 sudo,

$ make install

就是這樣。 OpenSSL 已成功安裝。 您可以運行 version 命令來查看它是否有效,如下所示:

$ /usr/local/openssl/bin/openssl version

OpenSSL 1.0.1g 7 Apr 2014

另一種在 Ubuntu 上從源代碼安裝 openssl 庫的方法,請按照以下步驟操作,這里的WORKDIR是您的工作目錄:

sudo apt-get install pkg-config
cd WORKDIR
git clone https://github.com/openssl/openssl.git
cd openssl
./config
make
sudo make install
# Open file /etc/ld.so.conf, add a new line: "/usr/local/lib" at EOF
sudo ldconfig

你想要openssl-devel包。 至少我認為它是-devel在 Ubuntu 上。 可能是-dev 這是兩者之一。

作為一般規則,當在 Debian 或 Ubuntu 上丟失開發文件(或任何其他文件)時,請使用apt-file找出提供該文件的軟件包:

~ apt-file search openssl/bio.h
android-libboringssl-dev: /usr/include/android/openssl/bio.h
libssl-dev: /usr/include/openssl/bio.h
libwolfssl-dev: /usr/include/cyassl/openssl/bio.h
libwolfssl-dev: /usr/include/wolfssl/openssl/bio.h

快速瀏覽該命令返回的每個包,使用apt show將告訴您哪些包是您要查找的包:

~ apt show libssl-dev
Package: libssl-dev
Version: 1.1.1d-2
Priority: optional
Section: libdevel
Source: openssl
Maintainer: Debian OpenSSL Team <pkg-openssl-devel@lists.alioth.debian.org>
Installed-Size: 8,095 kB
Depends: libssl1.1 (= 1.1.1d-2)
Suggests: libssl-doc
Conflicts: libssl1.0-dev
Homepage: https://www.openssl.org/
Tag: devel::lang:c, devel::library, implemented-in::TODO, implemented-in::c,
 protocol::ssl, role::devel-lib, security::cryptography
Download-Size: 1,797 kB
APT-Sources: http://ftp.fr.debian.org/debian unstable/main amd64 Packages
Description: Secure Sockets Layer toolkit - development files
 This package is part of the OpenSSL project's implementation of the SSL
 and TLS cryptographic protocols for secure communication over the
 Internet.
 .
 It contains development libraries, header files, and manpages for libssl
 and libcrypto.

N: There is 1 additional record. Please use the '-a' switch to see it
  1. 去官網下載你需要的版本的源碼

  2. 然后解壓更新包,執行以下命令

    ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl -Wl,-rpath,/usr/local/ssl/lib shared

因為默認只生成靜態庫,如果要動態庫,添加“shared”選項

  1. make && make install

所有這些答案都非常過時,並且從包仍在開發時開始。 您現在可以使用下面列出的“正常”命令:

sudo apt install openssl

sudo apt-get install libcurl4-openssl-dev

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM