Ubuntu 22.04 安装 easy-rsa 3.2.7 指南

Ubuntu 22.04 安装 easy-rsa 3.2.7 双路径实测:apt 3.0.8 与官方 tarball 3.2.7 安装对比、PKI 初始化与 build-ca 全流程回显、升级多版本管理与排障 FAQ。

easy-rsaPKI 证书信息安全Ubuntu22.042026/10/28

Ubuntu 22.04 安装 easy-rsa 3.2.7 指南

目标:在 Ubuntu 22.04 服务器上从零安装 easy-rsa 并完成 PKI 初始化与根 CA 构建,覆盖 apt 在线安装与官方 tarball 两种路径的全流程实测。本文全部命令与回显在 Ubuntu 22.04.5 LTS(x86_64,OpenSSL 3.0.2)实机验证通过,主线版本为 easy-rsa v3.2.7(官方 GitHub Releases 最新稳定版,查询日期 2026-10-28)。

一、环境信息

  • 操作系统:Ubuntu 22.04.5 LTS(x86_64)
  • OpenSSL:OpenSSL 3.0.2 15 Mar 2022(Ubuntu 22.04 自带,easy-rsa 的核心依赖)
  • easy-rsa 版本:
    • 方案 A(apt):easy-rsa 3.0.8-1ubuntu1(jammy/universe 官方源)
    • 方案 B(官方 tarball):EasyRSA-3.2.7.tgz(GitHub Releases 最新稳定版)
  • 安装目录:方案 A 由 dpkg 装入 /usr/share/easy-rsa/;方案 B 手工部署到 /opt/easy-rsa/3.2.7/
  • PKI 工作目录:各方案内的 pki/(easyrsa init-pki 自动创建)
  • 验证日期:2026-10-28

二、前置条件

2.1 系统依赖

easy-rsa 本体只是一个 shell 脚本包,但对 OpenSSL 有硬依赖——新装的最小化系统若未带 openssl,easyrsa --version 会直接报错(实测排障见 8.1 节)。先确认两个依赖:

openssl version    # 确认 OpenSSL 可执行
echo $SHELL        # 确认有 bash 或 dash(Ubuntu 默认满足)

实测回显:

OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
/bin/bash

若 openssl 不存在则先安装:

apt-get update
apt-get install -y openssl wget    # openssl 必装;wget 供方案 B 下载用

2.2 权限与目录规划

  • PKI 目录内含 CA 私钥(pki/private/ca.key),建议用普通用户操作、目录权限 0700(easy-rsa 默认 umask 077,创建的私钥文件自动为 0600);
  • 方案 B 的安装根目录建议 /opt/easy-rsa/<版本>/,同一台机器可并存多个版本目录,便于升级与回退。

三、版本选型说明

两条安装路径的版本差异是选型关键(均在实机上验证):

维度方案 A:apt 安装方案 B:官方 tarball
版本3.0.8-1ubuntu1(2020-09-09 构建)3.2.7(2026-09-19 构建,Git Commit bab739d1)
获取方式apt install easy-rsaGitHub Releases 下载 tgz
文件布局/usr/share/easy-rsa/(easyrsa 与 x509-types 由 make-cadir 软链)/opt/easy-rsa/3.2.7/ 自包含
vars 文件make-cadir 生成的目录内自带实体 vars(默认全注释)tarball 内为 vars.example,需改名 vars 才生效
新版特性无 revoke-issued/revoke-expired(吊销只有旧 revoke)有 revoke-issued 系列、gen-tls-crypt-key、serial、display-dn 等
升级便利性随系统源更新( jammy 源不再升级)换目录即可多版本并存

关键差异解读:apt 版胜在「一条命令装好、依赖自动就位」,但 3.0.8 与 3.2.7 相差六年功能演进;tarball 版需要手工下载与部署,却能拿到全部新特性且多版本并存。生产建议选方案 B,下文两种方案都给出完整实测过程。

四、安装方案 A:apt 在线安装

本方案适合希望用系统包管理器统一维护、且不需要 3.2.x 新特性的场景。apt 源里的包除脚本外还会自动补齐 openssl 依赖。

4.1 安装

apt-get update
apt-get install -y easy-rsa

实测回显(节选):

Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  easy-rsa
Setting up easy-rsa (3.0.8-1ubuntu1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.15) ...

4.2 查看包文件布局

dpkg -L easy-rsa | head -14

实测回显:

/.
/usr
/usr/bin
/usr/bin/make-cadir
/usr/share
/usr/share/doc
/usr/share/doc/easy-rsa
/usr/share/doc/easy-rsa/NEWS.Debian.gz
/usr/share/doc/easy-rsa/README.Debian
/usr/share/doc/easy-rsa/changelog.Debian.gz
/usr/share/doc/easy-rsa/copyright
/usr/share/doc/easy-rsa/doc
/usr/share/doc/easy-rsa/doc/EasyRSA-Advanced.md.gz
/usr/share/doc/easy-rsa/doc/EasyRSA-Readme.md.gz

apt 布局的要点:主脚本在 /usr/share/easy-rsa/easyrsa,并额外提供 /usr/bin/make-cadir 帮助命令——用于生成一个「链接到系统脚本」的 CA 工作目录。

4.3 用 make-cadir 创建 CA 工作目录

make-cadir /opt/apt-easyrsa
cd /opt/apt-easyrsa
ls -la

实测回显:

total 28
drwx------ 2 root root 4096 Oct 28 05:19 .
drwxr-xr-x 1 root root 4096 Oct 28 05:19 ..
lrwxrwxrwx 1 root root   27 Oct 28 05:19 easyrsa -> /usr/share/easy-rsa/easyrsa
-rw-r--r-- 1 root root 4616 Oct 28 05:19 openssl-easyrsa.cnf
-rw-r--r-- 1 root root 8925 Oct 28 05:19 vars
lrwxrwxrwx 1 root root   30 Oct 28 05:19 x509-types -> /usr/share/easy-rsa/x509-types

布局解读:easyrsa 与 x509-types 是指向系统目录的软链(升级系统包即生效);vars 是实体文件(可直接编辑,默认内容全部为注释态);openssl-easyrsa.cnf 也是实体文件。后续配置改法见本专栏配置详解篇(文末参考链接)。

4.4 初始化 PKI 并构建 CA(3.0.8 实测)

./easyrsa init-pki

实测回显(3.0.8 的文案与 3.2.7 略有差异):

init-pki complete; you may now create a CA or requests.
Your newly created PKI dir is: /opt/apt-easyrsa/pki

构建根 CA,过程中会两次要求输入 CA 私钥口令、一次输入 Common Name(本文演示口令统一用 q1w2e3r4、CA 名 apt-easyrsa-ca,生产请换强口令):

./easyrsa build-ca

实测回显(节选,... 处为密钥生成的随机点阵输出):

Enter New CA Key Passphrase:
Confirm New CA Key Passphrase:
...
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:apt-easyrsa-ca
CA creation complete and you may now import and sign cert requests.
Your new CA certificate file for publishing is at:
/opt/apt-easyrsa-test/pki/ca.crt

验证 CA 证书:

openssl x509 -in pki/ca.crt -noout -subject -dates

实测回显:

subject=CN = apt-easyrsa-ca
notBefore=Oct 28 05:28:12 2026 GMT
notAfter=Oct 25 05:28:12 2036 GMT

方案 A 到此可用:默认 10 年期 CA、CN-only DN 模式,后续签发命令与 3.2.7 基本一致(差异见第八章 FAQ)。

五、安装方案 B:官方 tarball 安装(推荐,3.2.7)

本方案直接使用官方 GitHub Releases 的最新稳定版,适合需要新特性(revoke-issued、gen-tls-crypt-key 等)与多版本并存的场景。

5.1 下载与校验

wget -O /tmp/EasyRSA-3.2.7.tgz https://github.com/OpenVPN/easy-rsa/releases/download/v3.2.7/EasyRSA-3.2.7.tgz
sha256sum /tmp/EasyRSA-3.2.7.tgz

实测回显:

308743bc9fe871b902d47dbe98d749daff3a05b27531684f02625ce7208d4598  /tmp/EasyRSA-3.2.7.tgz

⚠️ 网络说明:官方源 github.com 直连下载在本次实测环境正常可用(约 70KB 级别的包,秒下)。若你的服务器访问 GitHub 缓慢,可改走代理或国内可达下载渠道,下载后务必核对 sha256 再继续。

5.2 解压部署到 /opt/easy-rsa/3.2.7

mkdir -p /opt/easy-rsa
tar xf /tmp/EasyRSA-3.2.7.tgz -C /opt/easy-rsa
mv /opt/easy-rsa/EasyRSA-3.2.7 /opt/easy-rsa/3.2.7
ls /opt/easy-rsa/3.2.7/

实测回显:

COPYING.md
ChangeLog
README.md
README.quickstart.md
doc
easyrsa
gpl-2.0.txt
openssl-easyrsa.cnf
vars.example
x509-types

⚠️ 若解压时出现 tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.com.apple.metadata:kMDItemTextContentLanguage' 警告,属官方包在 macOS 上打包残留的扩展属性,可忽略,不影响使用(3.2.7 实测出现该提示,解压结果完整)。

5.3 版本验证

cd /opt/easy-rsa/3.2.7
./easyrsa --version

实测回显:

EasyRSA Version Information
Version:     3.2.7
Generated:   Sat Sep 19 07:53:22 CDT 2026
SSL Lib:     OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
Git Commit:  bab739d176a00f47819c79792863b13f4487b0c0
Source Repo: https://github.com/OpenVPN/easy-rsa

SSL Lib 行显示 easy-rsa 实际调用的 OpenSSL 版本,确认与你系统的一致即依赖就绪。

5.4 初始化 PKI

cd /opt/easy-rsa/3.2.7
./easyrsa init-pki

实测回显:

Notice
------
'init-pki' complete; you may now create a CA or requests.

Your newly created PKI dir is:
* /opt/easy-rsa/3.2.7/pki

查看 PKI 初始布局:

ls pki/

实测回显:

ca.crt   certs_by_serial  index.txt  issued  private  reqs  revoked  serial  vars.example
  • index.txt:OpenSSL CA 数据库(签发/吊销台账);
  • serial:当前序列号游标(3.2.x 默认随机 128bit 序列号);
  • vars.example:init-pki 时从上级目录复制的配置样例(仍是注释态,不生效)。

5.5 构建根 CA(交互实录)

./easyrsa build-ca

交互过程实测回显(口令两遍输入 q1w2e3r4,CN 输入 pki-server;Could not disable echo 警告出现在非交互终端,正常 SSH 终端不会显示口令明文):

Enter New CA Key Passphrase:
Confirm New CA Key Passphrase:
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:pki-server
Notice
------
CA creation complete. Your new CA certificate is at:
* /opt/easy-rsa/3.2.7/pki/ca.crt

Build-ca completed successfully.

验证 CA 关键属性:

openssl x509 -in pki/ca.crt -noout -subject -issuer -dates
openssl x509 -in pki/ca.crt -noout -text | grep -E 'Signature Algorithm|Public-Key' | head -2

实测回显:

subject=CN = pki-server
issuer=CN = pki-server
notBefore=Oct 28 05:11:07 2026 GMT
notAfter=Oct 25 05:11:07 2036 GMT
        Signature Algorithm: sha256WithRSAEncryption
                Public-Key: (2048 bit)

结果解读:默认配置下 CA 为 RSA 2048 + sha256、有效期 3650 天(10 年)、subject 仅含 CN(cn_only DN 模式默认值)。这些都可通过 vars 文件调整,详见本专栏配置参数详解篇。

5.6 产出物与权限

ls -l pki/private/

实测回显:

total 8
-rw------- 1 root root 1854 Oct 28 05:11 ca.key

CA 私钥自动为 0600 权限。pki/private/ca.key 是整套 PKI 的根信任,务必离线备份并限制访问;pki/ca.crt 则需要分发给所有验证方。

💡 说明:easy-rsa 是纯命令行工具,没有守护进程,因此不存在 systemd 服务托管环节——「安装完成」的标志就是 easyrsa --version 正常输出且 CA 构建成功。若需定期任务(如 CRL 续期)可自行配置 cron 调用对应命令。

六、多方案对比与选择建议

维度方案 A(apt 3.0.8)方案 B(tarball 3.2.7)
是否需联网需访问 Ubuntu 源需访问 GitHub Releases(或代理)
安装方式apt install + make-cadirwget + tar + mv
版本新旧2020 年 3.0.82026 年 3.2.7
吊销命令仅 revokerevoke-issued/revoke-expired(revoke 已废弃)
多版本并存不便(系统单包)天然支持(目录隔离)
升级随 apt 源(jammy 已冻结)换新目录软链切换
适合场景快速体验、旧流程兼容生产、新特性、OpenVPN 配套

选择建议:可联网且要长期使用选方案 B;内网 apt 软件源可用而 GitHub 不可达、且只用基础功能时选方案 A。两者不要混装在同机同目录,避免 PATH 与软链混乱。

七、升级、降级与多版本管理

  • 升级(方案 B):下载新版 tarball 解压为 /opt/easy-rsa/<新版本>/,将现有 pki/ 目录复制或移动到新版本目录下(或用 --pki=/path/to/pki 指向原目录),跑 ./easyrsa --version 确认即可;PKI 数据库格式跨 3.x 兼容,官方仓库 doc/ 下另有 EasyRSA-Upgrade-Notes.md 说明跨版本注意事项;
  • 降级:同升级,把 --pki 指回旧版本目录即可,建议先整目录备份 pki/;
  • 软链切换:维护 /opt/easy-rsa/current -> 3.2.7 软链,脚本与 cron 一律引用 current,版本切换只改软链。

八、常见问题(FAQ)

Q1:easyrsa --version 报 OpenSSL must either exist in your PATH or be defined in your vars file?

实测现象(最小化系统未装 openssl 时):

EasyRSA version 3.2.7

Error
-----
* OpenSSL must either exist in your PATH
  or be defined in your vars file.

Invalid SSL output for 'version':

./easy-rsa-3.2.7/easyrsa: 1325: openssl: not found

解决:apt-get install -y openssl 后重试。若系统有多个 OpenSSL(如自定义编译版),在 vars 中用 set_var EASYRSA_OPENSSL "/path/to/openssl" 显式指定。

Q2:解压出现 Ignoring unknown extended header keyword 'LIBARCHIVE.xattr...'?

官方 tarball 在 macOS 上打包带入的扩展属性,GNU tar 不识别但会忽略,属无害警告,解压结果完整(见 5.2 节实测),可安全继续。

Q3:改了 vars.example 不生效?

easy-rsa 只读取名为 vars 的文件:方案 B 需 cp vars.example vars 再编辑;方案 A 的 make-cadir 目录已自带实体 vars 直接编辑即可。文件名错误(如 vars.txt)时 easy-rsa 静默使用内置默认值,这是最常见的「配置不生效」原因。验证方法:init-pki 回显中若出现 Using Easy-RSA Auto-configured 'vars' file: 提示即表明 vars 已被识别。

Q4:build-ca 时口令回显在屏幕上?

在非交互终端(管道、部分自动化环境)easy-rsa 无法关闭回显,会打印 WARNING: Could not disable echo. Password will be shown on screen!。正常 SSH 交互终端无此问题;自动化场景改用 --passin/--passout 传参避免口令落屏。

Q5:apt 版与 tarball 版命令报错不一致(如 revoke 提示 DEPRECATED)?

3.2.x 将裸 revoke 标记为 DEPRECATED,推荐 revoke-issued/revoke-expired/revoke-renewed;3.0.8(apt 版)只有 revoke。以你实机版本的 ./easyrsa help 输出为准,跨版本脚本迁移时注意此差异。

九、卸载与清理

方案 A(apt):

apt-get remove --purge -y easy-rsa   # 卸载包
rm -rf /opt/apt-easyrsa              # 手工删除 make-cadir 创建的工作目录(含 pki 数据)

方案 B(tarball):

rm -rf /opt/easy-rsa    # 删除全部版本目录与 PKI 数据

⚠️ pki/ 目录含 CA 私钥与全部证书台账,删除前确认已按需备份 pki/ca.crt、pki/issued/、pki/private/(或整目录 tar 归档加密保存)。

十、参考链接

站内延伸阅读: