easy-rsa 3.2.7 常用 CLI 命令与工具详解

easy-rsa 3.2.7 全命令实测详解:建 CA→签发→异机导入→吊销→CRL→DH→导出分发全流程真实回显,含交互顺序、serial 大小写、gen-tls-crypt-key 依赖 openvpn 等排障实录与 nginx TLS 端到端验证。

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

easy-rsa 3.2.7 常用 CLI 命令与工具详解

目标:以一次完整 PKI 生命周期为主线(建 CA → 签发服务端/客户端证书 → 异机请求导入 → 吊销与 CRL → DH 参数 → 导出分发 → 端到端验证),逐条实测 easy-rsa 3.2.7 全部常用命令的真实交互与回显,并沉淀排障实录。本文全部命令与回显在 Ubuntu 22.04.5 LTS(OpenSSL 3.0.2)+ easy-rsa v3.2.7 实机验证通过(验证日期 2026-10-28)。

一、环境信息

  • 操作系统:Ubuntu 22.04.5 LTS(x86_64)
  • OpenSSL:3.0.2 15 Mar 2022;OpenVPN:2.5.11(gen-tls-crypt-key 依赖,见 4.10)
  • easy-rsa:v3.2.7(官方 tarball,安装目录 /opt/easy-rsa/3.2.7/)
  • CA 工作目录:/opt/easy-rsa/3.2.7/(PKI 目录 pki/);另备一台「客户端服务器」目录 /opt/easy-rsa-3.2.7/(演示异机 import-req,仅装 easy-rsa 与 openssl,无 CA)
  • 演示约定:CA 口令与私钥口令统一 q1w2e3r4(生产务必换强口令);CA CN 为 pki-server
  • 验证日期:2026-10-28

二、工具概览

easy-rsa 只有一个入口命令 easyrsa,格式为:

./easyrsa [全局选项] <子命令> [参数] [命令选项]

⚠️ 顺序硬规则:全局选项(--pki、--batch、--days 等)必须放在子命令之前,放在后面会被当作未知命令报错。

命令全景(./easyrsa help 实测节选,共 40+ 子命令):

Command list:

  init-pki [ cmd-opts ]
  self-sign-server <file_name_base> [ cmd-opts ]
  self-sign-client <file_name_base> [ cmd-opts ]
  build-ca [ cmd-opts ]
  gen-dh
  gen-req <file_name_base> [ cmd-opts ]
  sign-req <type> <file_name_base> [ cmd-opts ]
  build-client-full <file_name_base> [ cmd-opts ]
  build-server-full <file_name_base> [ cmd-opts ]
  build-serverClient-full <file_name_base> [ cmd-opts ]
  inline <file_name_base>
  expire <file_name_base>
  renew-ca
  renew <file_name_base>
  revoke <file_name_base> [ cmd-opts ]          # DEPRECATED
  revoke-issued <file_name_base> [ cmd-opts ]   # REPLACEMENT
  revoke-expired <file_name_base> [ cmd-opts ]
  revoke-renewed <file_name_base> [ cmd-opts ]
  gen-crl
  update-db
  show-req <file_name_base> [ cmd-opts ]
  show-cert <file_name_base> [ cmd-opts ]
  show-ca [ cmd-opts ]
  show-crl
  show-expire <file_name_base> (Optional)
  show-revoke <file_name_base> (Optional)
  show-renew <file_name_base> (Optional)
  verify-cert <file_name_base>
  import-req <request_file_path> <short_name_base>
  import-ca <DIR/FILE_NAME>
  import-tls-key <DIR/FILE_NAME>
  export-p1 <file_name_base> [ cmd-opts ]
  export-p7 <file_name_base> [ cmd-opts ]
  export-p8 <file_name_base> [ cmd-opts ]
  export-p12 <file_name_base> [ cmd-opts ]
  set-pass <file_name_base> [ cmd-opts ]
  gen-tls-auth-key / gen-tls-crypt-key
  write <TYPE>
  serial|check-serial <SERIAL>
  display-dn <FORM> <DIR/FILE_NAME>
  show-eku <file_name_base>|<DIR/FILE_NAME>
  rand <Decimal-Number>

两类签发路径的选择:分步式(gen-req → sign-req,CSR 可异机流转,权限分离清晰)与一步式(build-*-full,CA 机上直接生成并签发,适合自助场景)。生产建议分步式:私钥永远不离开端侧机器。

三、前置条件

四、各命令详解(全流程实测)

4.1 gen-req:生成私钥与证书请求

在端侧(或 CA 机演练)为服务器 server 生成密钥对与 CSR。交互共 3 次输入:私钥口令两遍 + CN(回车默认 server):

./easyrsa gen-req server

实测回显(节选,+ 点阵为 openssl 密钥生成噪声,每台机器不同):

Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
Common Name (eg: your user, host, or server name) [server]:
Notice
------
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /opt/easy-rsa/3.2.7/pki/reqs/server.req
* key: /opt/easy-rsa/3.2.7/pki/private/server.key

产物解读:reqs/server.req 是可外送的 CSR(无私钥信息,可公开传输);private/server.key 是加密私钥,绝不能外送。客户端证书同理:./easyrsa gen-req client1。

4.2 sign-req:CA 签发证书

CA 侧对 server 的请求签发 server 类型证书。交互共 2 次:先输入 yes 确认请求摘要,再输 CA 口令:

./easyrsa sign-req server server

实测回显:

Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
You are about to sign the following certificate:

  Requested CN:     'server'
  Requested type:   'server'
  Valid for:        '825' days


subject=
    commonName                = server

Type the word 'yes' to continue, or any other input to abort.
  Confirm requested details: yes
Using configuration from /opt/easy-rsa/3.2.7/pki/1119895f/temp.00
Enter pass phrase for /opt/easy-rsa/3.2.7/pki/private/ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName            :ASN.1 12:'server'
Certificate is to be certified until Jan 30 05:12:27 2029 GMT (825 days)

Write out database with 1 new entries
Data Base Updated

WARNING
=======
INCOMPLETE Inline file created:
* /opt/easy-rsa/3.2.7/pki/inline/private/server.inline

Missing TLS Key, see 'easyrsa help gen-tls'


Notice
------
Certificate created at:
* /opt/easy-rsa/3.2.7/pki/issued/server.crt

要点:

  • <type> 合法值即 x509-types 模板名:ca/client/server/serverClient/code-signing/email/kdc;
  • Valid for: '825' days 来自 EASYRSA_CERT_EXPIRE 默认值;临时改期用全局选项 --days=30;
  • 回显尾部 WARNING 属正常:inline 文件缺 TLS Key 段(补齐见 4.10);INCOMPLETE Inline file created 的 inline 文件此时仅含 cert/key/ca 段;
  • 签发后 CA 数据库(pki/index.txt)追加一条 V(Valid)记录,pki/issued/、pki/certs_by_serial/ 各落一份证书。

客户端签发同构:./easyrsa sign-req client client1,回显同样为 Confirm requested details: yes → CA 口令 → Certificate created at: /opt/easy-rsa/3.2.7/pki/issued/client1.crt。

4.3 import-req:导入异机请求(离线 CA 标准姿势)

真实场景中 CSR 在客户端机器上生成后送达 CA 机。实测环境:在另一台只装 easy-rsa 的客户端服务器上生成 laptop-alice 请求,再用安全渠道(U 盘/scp 均可,本文实测经受控共享目录中转)把 laptop-alice.req 送到 CA 机。

客户端服务器上执行:

cd /opt/easy-rsa-3.2.7
./easyrsa init-pki
./easyrsa gen-req laptop-alice    # 口令两遍 + CN 回车
openssl req -in pki/reqs/laptop-alice.req -noout -subject

实测回显:

subject=CN = laptop-alice

CA 服务器上导入并签发(导入只需短名,不需要口令):

./easyrsa import-req /share/laptop-alice.req laptop-alice

实测回显:

Notice
------
Request successfully imported with short-name: laptop-alice
This request is now ready to be signed.

随后正常签发:

./easyrsa sign-req client laptop-alice

实测回显(尾部):

Notice
------
Certificate created at:
* /opt/easy-rsa/3.2.7/pki/issued/laptop-alice.crt

签名后的证书再传回客户端。注意:import-req 导入的请求与本地生成的请求在 sign-req 环节完全同权。

4.4 show-* 系列:查看请求/证书/CA/CRL

查看请求(show-req)与已签证书(show-cert):

./easyrsa show-req server
./easyrsa show-cert server

show-cert server 实测回显(节选):

Notice
------
Showing 'cert' details for: 'server'

This file is stored at:
* /opt/easy-rsa/3.2.7/pki/issued/server.crt


Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            7f:a2:c0:28:5b:cd:41:95:f6:d3:41:92:89:5c:0a:57
        Signature Algorithm: sha256WithRSAEncryption
        Issuer:
            commonName                = pki-server
        Validity
            Not Before: Oct 28 05:12:27 2026 GMT
            Not After : Jan 30 05:12:27 2029 GMT
        Subject:
            commonName                = server
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
            X509v3 Key Usage:
                Digital Signature, Key Encipherment

show-ca 输出 CA 证书详情(含 X509v3 Basic Constraints: critical、CA:TRUE),show-crl 输出 CRL 详情(见 4.7),show-revoke client1 输出吊销台账行:

R | Serial: 063E9AF7AAC214D21329CE127C61FAE4 | Revoked: 2026-10-28 05:14:01Z | Reason: None given | CN: client1

4.5 verify-cert:校验证书状态

./easyrsa verify-cert server
./easyrsa verify-cert laptop-alice

实测回显:

/opt/easy-rsa/3.2.7/pki/issued/server.crt: OK

Notice
------
  Certificate name:    server
  Verification status: GOOD

/opt/easy-rsa/3.2.7/pki/issued/laptop-alice.crt: OK

Notice
------
  Certificate name:    laptop-alice
  Verification status: GOOD

注意 verify-cert 只查 pki/issued/ 内文件;吊销后原文件被移走,对该名再跑会报 No certificate found(见 4.6)。

4.6 revoke-issued 与 gen-crl:吊销与吊销列表

吊销 client1(交互同样先 yes 后 CA 口令):

./easyrsa revoke-issued client1

实测回显:

    Continue with revocation: yes
Using configuration from /opt/easy-rsa/3.2.7/pki/1802e39f/temp.00
Enter pass phrase for /opt/easy-rsa/3.2.7/pki/private/ca.key:
Revoking Certificate 063E9AF7AAC214D21329CE127C61FAE4.
Data Base Updated

Notice
------
                    * IMPORTANT *

Revocation was successful. You must run 'gen-crl' and upload
a new CRL to your infrastructure in order to prevent the revoked
certificate from being accepted.

吊销动作本身不会让证书失效——必须紧跟着生成新 CRL 并分发:

./easyrsa gen-crl

实测回显:

An updated CRL has been created:
* /opt/easy-rsa/3.2.7/pki/crl.pem

IMPORTANT: When the CRL expires, an OpenVPN Server which uses a
CRL will reject ALL new connections, until the CRL is replaced.

验证吊销效果的三层证据(实测):

# 1) 台账视角:证书从 issued 移入 revoked(按序列号归档)
ls pki/revoked/certs_by_serial/
# → 063E9AF7AAC214D21329CE127C61FAE4.crt

# 2) CRL 内容视角
./easyrsa show-crl
# 节选:
# Revoked Certificates:
#     Serial Number: 063E9AF7AAC214D21329CE127C61FAE4
#         Revocation Date: Oct 28 05:14:01 2026 GMT

# 3) 密码学校验视角(openssl 直接做 CRL 检查)
openssl verify -CAfile pki/ca.crt -crl_check -CRLfile pki/crl.pem \
  pki/revoked/certs_by_serial/063E9AF7AAC214D21329CE127C61FAE4.crt

第 3 步实测回显:

CN = client1
error 23 at 0 depth lookup: certificate revoked
error pki/revoked/certs_by_serial/063E9AF7AAC214D21329CE127C61FAE4.crt: verification failed

error 23: certificate revoked 即密码学层面的吊销生效证明。

4.7 gen-dh:生成 Diffie-Hellman 参数

OpenVPN RSA 模式的必需产物(tls-crypt/ECDH 现代部署可省):

./easyrsa gen-dh

实测回显(RSA 2048,实机耗时 6.7 秒,旧硬件可能需数分钟):

DH parameters appear to be ok.

Notice
------

DH parameters of size 2048 created at:
* /opt/easy-rsa/3.2.7/pki/dh.pem

产物即 OpenVPN 服务端配置 dh dh.pem 引用的文件。

4.8 export-p12:打包客户端证书分发件

把 laptop-alice 的证书、私钥、CA 链打包成 PKCS#12(OpenVPN 客户端/浏览器导入常用)。交互共 3 次:确认 yes → PKCS#12 导出口令 → (沿用私钥口令):

./easyrsa export-p12 laptop-alice

实测回显(尾部):

A BASE64 encoded inline file has also been created at:
* /opt/easy-rsa/3.2.7/pki/inline/private/laptop-alice.p12-inline


Notice
------
Successful export of p12 file. Your exported file is at:
* /opt/easy-rsa/3.2.7/pki/private/laptop-alice.p12

同族命令:export-p1(PKCS#1 PEM)、export-p7(PKCS#7 链)、export-p8(PKCS#8),按对接系统的格式要求选用。

4.9 inline:生成 OpenVPN 可内嵌的文本块

inline 命令把证书体系拼装成 <cert>/<key>/<ca>/<dh>/<tls-auth> 文本段,可直接粘进 .ovpn 配置。签发时自动生成的 inline 文件实测头部:

# Easy-RSA Inline file
# Certificate type: client
# commonName: laptop-alice
# SHA256 fingerprint:
# 41:D4:45:9D:E0:16:C2:87:2C:D5:27:3F:47:A8:51:5A:CB:B8:68:08:BB:96:C6:BF:83:98:DD:02:6C:4A:0B:4D

<cert>
-----BEGIN CERTIFICATE-----
...
</cert>

# When you recieve your key place it in the
# 'pki/private' sub-dir of your PKI and use command 'inline'
# to rebuild this inline file with your key.
# <key>
# * Paste your private key here *
# </key>

<ca>
-----BEGIN CERTIFICATE-----
...
</ca>

# <dh>
# * Paste your Diffie-Hellman parameters file here *
# </dh>

# Easy-RSA TLS Key not found!

生成 TLS Key 后重新执行 ./easyrsa inline laptop-alice,<tls-auth>/TLS Key 段即被填充。私钥缺失时(如 CA 侧无客户端私钥)对应段保持占位注释——这正是签发时 INCOMPLETE inline 警告的含义。

4.10 gen-tls-crypt-key:生成 TLS 控制信道密钥

./easyrsa gen-tls-crypt-key

实测回显:

Notice
------
TLS-CRYPT Key generated at:
* /opt/easy-rsa/3.2.7/pki/private/easyrsa-tls.key

If this key is changed then it MUST be redistributed to ALL servers
AND clients, to be in effect. Do NOT change this existing file.

⚠️ 排障实录:未装 openvpn 的机器上执行会直接报错(实测原文):

EasyRSA version 3.2.7

Error
-----
An 'openvpn' binary is not in your system PATH.
EasyRSA can not generate OpenVPN TLS keys.

解决:apt-get install -y openvpn 后重试(该命令借助 openvpn 二进制完成密钥生成,属 easy-rsa 与 OpenVPN 的强耦合点)。同族命令 gen-tls-auth-key 生成传统 tls-auth 静态密钥。

4.11 build-*-full:一步式签发

CA 机上直接生成密钥+CSR 并签发(私钥留在 CA 机,仅适合 CA 机可信的自助场景)。实测 nopass 模式(私钥不加密):

./easyrsa build-server-full openvpn-server nopass

实测回显(尾部):

Notice
------
Certificate created at:
* /opt/easy-rsa/3.2.7/pki/issued/openvpn-server.crt

⚠️ 交互排障实录:该命令交互为「确认 yes → 新私钥口令(nopass 跳过)→ CA 口令」。实测在自动化喂入时若漏掉 CA 口令,openssl 会连续三次提示并报错(原文节选):

Enter pass phrase for /opt/easy-rsa/3.2.7/pki/private/ca.key:
Could not read CA private key from /opt/easy-rsa/3.2.7/pki/private/ca.key
Easy-RSA error:
easyrsa_openssl - Command has failed:
* openssl ca -utf8 -batch -in /opt/easy-rsa/3.2.7/pki/reqs/openvpn-server.req ...

规律总结:所有「确认 + 口令」混合交互的命令,输入顺序一律先确认词(yes)后口令。

同族:build-client-full <name> [nopass]、build-serverClient-full <name>(server+client 双 EKU)。

4.12 set-pass:修改私钥口令

./easyrsa set-pass server

实测回显(旧口令 → 新口令两遍):

Notice
------
Key passphrase successfully changed

加 nopass 命令选项可移除口令;注意对已吊销证书执行会报 Missing private key(实测原文见 4.13 吊销移位说明)。

4.13 查询辅助命令:serial / display-dn / show-eku / rand / write

序列号状态查询(serial 只接受小写十六进制):

./easyrsa serial 7fa2c0285bcd4195f6d34192895c0a57
./easyrsa serial 063e9af7aac214d21329ce127c61fae4

实测回显:

7FA2C0285BCD4195F6D34192895C0A57=Valid (V)

========================================
COMPLETE

063E9AF7AAC214D21329CE127C61FAE4=Revoked (R)

========================================
COMPLETE

⚠️ 实测排障:传大写序列号报 Invalid serial number: '7FA2C0285BCD4195F6D34192895C0A57'——脚本内部校验字符集只含小写 hex([!1234567890abcdef]),大写字母命中非法集。输出却回显大写,容易误导;记住「输入小写、输出大写」即可。

查看 DN(FORM 合法值为 req|x509):

./easyrsa display-dn x509 pki/issued/server.crt
./easyrsa display-dn req pki/reqs/server.req

实测回显:

subject=
    commonName                = server

EKU 查询:./easyrsa show-eku server → * Known X509v3 Extended Key Usage: 'server'。随机数:./easyrsa rand 16 → c0012d3982b0c70677b52d78c184a3e9(16 字节 hex)。write 命令输出类型模板内容:./easyrsa write ca 打印 ca 类型的 X509 扩展定义(basicConstraints = critical,CA:TRUE 等)。

4.14 端到端验证:用签发的证书给 nginx 配 TLS(可选加分实测)

证书最终要被 TLS 服务消费才算闭环。用 5.1 节 vars 定制(org 模式)签发的 web-server 证书实测:nginx 启用 443 SSL,引用证书/私钥并配 ssl_password_file(私钥有口令时 nginx 需要此指令或人工输入):

server {
    listen 443 ssl;
    server_name web-server;
    ssl_certificate     /etc/nginx/certs/web-server.crt;
    ssl_certificate_key /etc/nginx/certs/web-server.key;
    ssl_password_file   /etc/nginx/certs/key.pass;
    location / { return 200 'easy-rsa TLS OK\n'; add_header Content-Type text/plain; }
}

配置校验与客户端验证实测:

nginx -t          # → configuration file /etc/nginx/nginx.conf test is successful
# 私有 CA 签发的证书必须把 ca.crt 提供给客户端做信任锚:
curl -s --cacert /etc/nginx/certs/ca.crt --resolve web-server:443:127.0.0.1 https://web-server/

实测回显:

easy-rsa TLS OK

对照实验(实测):不带 --cacert 时 curl 退出码 60(无法校验自建 CA 签名);即使带 --cacert,但用 IP 直连(证书 CN=web-server 且无 IP SAN)同样报 exit 60 主机名不匹配——自建证书务必通过证书内 CN/SAN 覆盖的名称访问,或签发时用 --san IP:10.89.74.10 补齐。此次实测完整验证了「CA 签发 → 服务端部署 → 客户端信任链校验」链路真实可用。

五、OpenVPN 配合产出物清单

按 OpenVPN 服务端/客户端配置所需,easy-rsa 全流程产物对号入座:

OpenVPN 配置引用easy-rsa 产物生成命令分发范围
ca ca.crtpki/ca.crtbuild-ca全部端(公开)
cert server.crt / key server.keypki/issued/*.crt + pki/private/*.keygen-req + sign-req(或 build-server-full)各自端(私钥保密)
dh dh.pempki/dh.pemgen-dh服务端
crl-verify crl.pempki/crl.pemgen-crl(每次吊销后重生成)服务端
tls-crypt ta.keypki/private/easyrsa-tls.keygen-tls-crypt-key服务端+全部客户端
客户端一体包pki/private/<name>.p12 或 inline 文件export-p12 / inline对应客户端
.ovpn 内嵌块pki/inline/<name>.inline签发自动生成 / inline对应客户端

吊销运营闭环:revoke-issued <name> → gen-crl → 把新 crl.pem 分发到服务端 → verify-cert/show-revoke 复核。

六、注意事项

  1. 全局选项必须在子命令前:./easyrsa --days=30 sign-req ... 合法,./easyrsa sign-req ... --days=30 报未知命令;
  2. 交互顺序铁律:凡是「确认 + 口令」混合交互(sign-req/revoke-issued/export-p12/build-*-full),先输确认词 yes、后输口令;gen-req/build-ca 则是先口令后 DN 字段;
  3. CA 私钥零外送:pki/private/ca.key 只应存在于 CA 机;端侧只产生 CSR(gen-req);
  4. CRL 时效:CRL 过期会让引用它的 OpenVPN 服务端拒绝全部新连接(官方回显原文警告),把 gen-crl 纳入 cron(建议周期 ≤ EASYRSA_CRL_DAYS 的一半);
  5. 吊销三连:revoke 后必须 gen-crl 并分发,否则吊销不生效;revoke 旧命令已 DEPRECATED,统一用 revoke-issued/revoke-expired/revoke-renewed;
  6. 多 PKI 并存:用 --pki=/path 切换目录,或 cd 到对应 EasyRSA 工作目录执行,避免串库。

七、常见问题(FAQ)

Q1:sign-req 提示 Aborting without confirmation.?

确认环节没读到 yes。实测两种触发:管道喂入顺序颠倒(口令被 confirm 读走);或交互时输入了非 yes 词(任何其他输入都中止)。按 yes → CA 口令顺序重新执行即可。

Q2:verify-cert 报 No certificate found for the input?

该证书名已不在 pki/issued/(吊销或续期后文件被移动)。实测吊销后证书实际位于 pki/revoked/certs_by_serial/<序列号>.crt,用 show-revoke 查台账、用 openssl verify -crl_check 做密码学复核。

Q3:gen-tls-crypt-key 报 An 'openvpn' binary is not in your system PATH?

见 4.10 排障实录:安装 openvpn 包即可,这是 easy-rsa 生成 OpenVPN TLS 密钥的硬依赖。

Q4:display-dn cert ... 报 Invalid command?

FORM 参数写错了,合法值只有 req 与 x509(x509 指证书),实测 ./easyrsa display-dn x509 pki/issued/server.crt 正常。

Q5:签发时回显 INCOMPLETE Inline file created / Missing TLS Key?

不是错误:inline 文件在 TLS Key 未生成前先落了 cert/key/ca 段。执行 gen-tls-crypt-key(或 gen-tls-auth-key)后再 ./easyrsa inline <name> 重建即可补全。

Q6:3.0.x(apt 版)上找不到本文的某些命令?

serial、display-dn、revoke-issued、gen-tls-crypt-key 等为 3.1+/3.2.x 新增或改造命令,Ubuntu 22.04 apt 源的 3.0.8 不具备;按安装指南换用官方 tarball 版本。

八、参考链接

站内延伸阅读: