温馨提示×

linux openssl怎么启用

小樊
44
2026-09-19 20:58:56
栏目: 云计算

在 Linux 上“启用 OpenSSL”通常指 安装并使用 OpenSSL,或 启用某些加密功能 / 服务使用 OpenSSL。下面按常见场景说明:


一、检查 OpenSSL 是否已安装

openssl version

如果输出类似:

OpenSSL 3.0.2 15 Mar 2022

说明已安装。

如果提示 command not found,需要安装。


二、安装 OpenSSL(常见发行版)

1️⃣ Ubuntu / Debian

sudo apt update
sudo apt install openssl

2️⃣ CentOS / Rocky / AlmaLinux

sudo yum install openssl
# 或
sudo dnf install openssl

3️⃣ Arch Linux

sudo pacman -S openssl

三、命令行使用 OpenSSL(已“启用”)

生成私钥

openssl genrsa -out key.pem 2048

生成证书签名请求(CSR)

openssl req -new -key key.pem -out csr.pem

自签名证书

openssl x509 -req -days 365 -in csr.pem \
-signkey key.pem -out cert.pem

测试加密

echo "hello" | openssl enc -aes-256-cbc -a

四、让服务“启用 OpenSSL”(常见情况)

1️⃣ Nginx 启用 HTTPS(OpenSSL)

server {
    listen 443 ssl;
    ssl_certificate     /path/cert.pem;
    ssl_certificate_key /path/key.pem;
}

然后:

sudo nginx -t
sudo systemctl reload nginx

2️⃣ OpenSSH 使用 OpenSSL

OpenSSH 默认依赖 OpenSSL,一般无需额外启用
查看版本:

ssh -V

3️⃣ 编译程序时启用 OpenSSL

./configure --with-openssl
make

五、启用旧版/特定算法(注意安全)

某些旧算法默认被禁用(如 TLS 1.0、MD5):

openssl ciphers -v

如需启用(不推荐):

openssl s_client -tls1_0 -connect example.com:443

六、常见问题

❌ openssl: error while loading shared libraries

sudo ldconfig

❌ 版本太旧

openssl version

可源码编译新版(谨慎操作)。


如果你能具体说:

  • 命令行用
  • 还是 某个服务(Nginx / MySQL / SSH)
  • 还是 编译程序

我可以给你更精确的“启用”步骤。

0