OpenSSL命令速查
密钥生成、CSR 与自签证书、签发与校验、PEM/DER/PFX 转换、s_client 握手测试、加解密摘要与报错排查等 206 条命令
共 206 条命令 · 11 类场景 · 点击右侧图标可复制
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl version -a | 查看版本、编译时间与内置目录,确认是 1.1.1 还是 3.x | |
openssl help | 列出全部标准子命令 | |
openssl help enc | 查看某个子命令的可用参数 | |
openssl list -digest-algorithms | 列出可用摘要算法(sha256、sm3 等) | |
openssl list -cipher-algorithms | 列出可用对称算法 | |
openssl list -public-key-algorithms | 列出公钥算法(RSA、EC、ED25519 等) | |
openssl list -providers | 查看已加载 provider,排障 legacy 算法必用 | |
openssl list -kdf-algorithms | 列出可用 KDF(HKDF、PBKDF2、SCRYPT) | |
openssl list -mac-algorithms | 列出可用 MAC 算法(HMAC、CMAC) | |
openssl version -d | 输出默认配置目录,确认读的是哪个 openssl.cnf | |
openssl engine -t -c | 查看引擎可用状态,硬件加速卡场景用 | |
openssl enc -list | 列出 enc 子命令支持的对称算法 | |
pkg-config --modversion openssl | 查看开发库版本,编译依赖不一致时排查 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out key.pem | 通用私钥生成入口,3.x 推荐写法 | |
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out key4096.pem | 生成 4096 位 RSA 私钥 | |
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ec.key | 生成 ECDSA P-256 私钥,性能优于 RSA | |
openssl genpkey -algorithm ED25519 -out ed25519.key | 生成 Ed25519 私钥,签名快、密钥短 | |
openssl genpkey -algorithm X25519 -out x25519.key | 生成 X25519 私钥,用于密钥交换 | |
openssl genpkey -aes256 -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out enc.key | 生成带口令加密的私钥 | |
openssl genrsa -out rsa.key 2048 | 传统写法,仍可用但 3.x 建议改用 genpkey | |
openssl genrsa -aes256 -out rsa_enc.key 4096 | 生成加密的 4096 位私钥 | |
openssl pkey -in key.pem -pubout -out pub.pem | 从私钥导出 PEM 公钥(SubjectPublicKeyInfo) | |
openssl rsa -in key.pem -pubout -out pub.pem | RSA 专用导出公钥,与 pkey 等价 | |
openssl rsa -in key.pem -RSAPublicKey_out -out pub_pkcs1.pem | 导出 PKCS#1 格式公钥,兼容老客户端 | |
openssl pkey -in key.pem -noout -text | 查看私钥结构、位长与参数 | |
openssl pkey -in key.pem -pubin -noout -text | 查看公钥内容 | |
openssl rsa -in key.pem -check | 校验 RSA 私钥完整性,输出 RSA key ok | |
openssl pkey -in key.pem -aes256 -out key_enc.pem | 给已有明文私钥加口令 | |
openssl pkey -in key_enc.pem -out key_plain.pem | 输入口令解密私钥,注意文件权限 | |
openssl ecparam -list_curves | 列出支持的椭圆曲线名称 | |
openssl ecparam -name prime256v1 -genkey -noout -out ec.key | 生成 P-256 的 EC 私钥(老写法) | |
openssl ec -in ec.key -noout -text | 查看 EC 私钥曲线与公钥点 | |
openssl dhparam -out dh2048.pem 2048 | 生成 DH 参数,Nginx ssl_dhparam 使用 | |
openssl dhparam -dsaparam -out dh2048.pem 2048 | 快速生成 DH 参数,耗时从分钟级降到秒级 | |
openssl rsa -in key.pem -noout -modulus | openssl sha256 | 取私钥模数摘要,与证书模数比对是否配对 | |
ls -l key.pem | 部署后确认私钥权限为 600 且属主正确 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl req -new -key key.pem -out req.csr | 用已有私钥生成 CSR,交互填写主体信息 | |
openssl req -new -newkey rsa:2048 -nodes -keyout key.pem -out req.csr | 一步生成私钥 + CSR,-nodes 表示私钥不加口令 | |
openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -keyout ec.key -out ec.csr | 生成 ECDSA 私钥与 CSR | |
openssl req -new -key key.pem -out req.csr -subj "/C=CN/ST=Beijing/L=Beijing/O=Example/OU=IT/CN=example.com" | 非交互式填写主体,适合脚本化 | |
openssl req -new -key key.pem -out req.csr -addext "subjectAltName=DNS:example.com,DNS:*.example.com,IP:10.0.0.1" | 3.x 直接附加 SAN,浏览器只认 SAN | |
openssl req -new -key key.pem -out req.csr -sha256 -addext "subjectAltName=DNS:example.com" | 指定签名摘要,公有 CA 均已强制 SHA-256 | |
[req]
distinguished_name = dn
req_extensions = v3_req
prompt = no
[dn]
CN = example.com
[v3_req]
subjectAltName = @alt
[alt]
DNS.1 = example.com
DNS.2 = *.example.com
DNS.3 = www.example.com | san.cnf:多域名场景用配置文件更清晰 | |
openssl req -new -key key.pem -out req.csr -config san.cnf | 按配置文件生成带 SAN 的 CSR | |
openssl req -in req.csr -noout -text | 查看 CSR 主体、公钥与扩展信息 | |
openssl req -in req.csr -noout -verify | 校验 CSR 自签名是否有效 | |
openssl req -in req.csr -noout -subject -nameopt RFC2253 | 标准格式输出主体名,便于脚本解析 | |
openssl req -in req.csr -noout -pubkey | 从 CSR 提取公钥,核对与私钥是否同对 | |
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 365 | 生成自签名证书,测试环境最快方案 | |
openssl req -x509 -new -key ca.key -out ca.crt -days 3650 -subj "/CN=My Root CA" -addext "basicConstraints=critical,CA:TRUE" -addext "keyUsage=critical,keyCertSign,cRLSign" | 创建内网根 CA,必须带 CA:TRUE 才能签发下级证书 | |
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ca.key -out ca.crt -subj "/CN=Internal Root CA" | 一步生成根 CA 私钥与证书 | |
openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt -days 3650 | 用已有 CSR 自签成根证书 | |
openssl req -in req.csr -noout -text | grep -A1 "Subject Alternative Name" | 检查 CSR 是否真的带上了 SAN | |
openssl req -new -key key.pem -out new.csr -config san.cnf -multivalue-rdn | 主体含多值 RDN 时使用,避免转义问题 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl x509 -req -in req.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -sha256 | 用自建 CA 签发服务端证书 | |
openssl x509 -req -in req.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -extfile san.cnf -extensions v3_req | 签发时注入 SAN 等扩展,否则证书不带域名 | |
openssl x509 -req -in req.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -copy_extensions copy | 3.x 直接复制 CSR 中的扩展,最省事的做法 | |
openssl x509 -in cert.pem -noout -text | 查看证书完整内容:主体、有效期、扩展、指纹 | |
openssl x509 -in cert.pem -noout -dates -subject -issuer -serial | 一次性查看有效期、颁发者与被颁发者 | |
openssl x509 -in cert.pem -noout -fingerprint -sha256 | 输出 SHA-256 指纹,做证书一致性核对 | |
openssl x509 -in cert.pem -noout -pubkey | 提取证书公钥,与私钥比对 | |
openssl x509 -in cert.pem -noout -ext subjectAltName | 单独查看 SAN 列表,确认域名是否覆盖 | |
openssl x509 -in cert.pem -noout -ext basicConstraints,keyUsage,extendedKeyUsage | 查看用途限制,判断能否做服务端证书 | |
openssl x509 -in cert.pem -noout -checkend 86400 | 剩余有效期不足 1 天返回非零,适合巡检脚本 | |
openssl x509 -in cert.pem -noout -purpose | 判断证书可用于 SSL server/client 等哪些场景 | |
openssl x509 -in cert.pem -noout -ocsp_uri | 查看证书内嵌的 OCSP 地址 | |
openssl x509 -in cert.pem -noout -modulus | openssl sha256 | 取证书模数摘要,与私钥模数比对 | |
openssl x509 -in cert.pem -noout -text -certopt no_pubkey,no_sigdump | 精简输出,跳过冗长的公钥与签名块 | |
openssl verify -CAfile ca.crt server.crt | 用指定根证书校验服务端证书 | |
openssl verify -CAfile ca.crt -untrusted intermediate.crt server.crt | 带中间证书校验,链不全会报 unable to get local issuer | |
openssl verify -CApath /etc/ssl/certs cert.pem | 用系统证书目录校验公有证书 | |
openssl verify -show_chain -CAfile ca.crt server.crt | 3.x 输出完整校验链,定位缺哪一级 | |
openssl verify -attime 1700000000 -CAfile ca.crt server.crt | 按指定时间点校验,排查历史签发问题 | |
openssl crl -in crl.pem -noout -text | 查看吊销列表内容与下次更新时间 | |
openssl crl2pkcs7 -nocrl -certfile ca.crt -out ca.p7b | 把证书打包成 PKCS#7,供 Windows 导入 | |
openssl ocsp -issuer ca.crt -cert server.crt -url http://ocsp.example.com -resp_text | 手工查询 OCSP 吊销状态 | |
openssl ocsp -issuer ca.crt -cert server.crt -url http://ocsp.example.com -CAfile ca.crt -no_nonce | 带 CA 校验 OCSP 响应签名 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl dgst -sha256 file.txt | 计算文件 SHA-256 摘要 | |
openssl dgst -sha512 file.txt | 计算 SHA-512 摘要 | |
openssl dgst -sha256 -binary file.txt | openssl base64 | 输出 Base64 摘要,便于贴到工单或校验页 | |
openssl dgst -sha256 -sign key.pem -out sig.bin file.txt | 用私钥对文件摘要签名(RSA/ECDSA 通用) | |
openssl dgst -sha256 -verify pub.pem -signature sig.bin file.txt | 用公钥验签,输出 Verified OK | |
openssl dgst -sha256 -prverify key.pem -signature sig.bin file.txt | 用私钥验签,仅本地自查用 | |
openssl dgst -sha256 -hmac "mysecret" file.txt | HMAC 计算,接口签名联调常用 | |
openssl pkeyutl -sign -inkey key.pem -rawin -digest sha256 -in file.txt -out sig.bin | 3.x 推荐的签名写法,摘要由工具内部完成 | |
openssl pkeyutl -verify -pubin -inkey pub.pem -rawin -digest sha256 -in file.txt -sigfile sig.bin | 与上一条配套的验签命令 | |
openssl pkeyutl -encrypt -pubin -inkey pub.pem -in secret.txt -out secret.enc | RSA 公钥加密小数据(受密钥长度限制) | |
openssl pkeyutl -decrypt -inkey key.pem -in secret.enc -out secret.txt | RSA 私钥解密 | |
openssl smime -sign -in msg.txt -signer cert.pem -inkey key.pem -out signed.p7m | S/MIME 签名邮件内容 | |
openssl smime -verify -in signed.p7m -CAfile ca.crt -out msg.txt | 校验 S/MIME 签名并还原原文 | |
openssl cms -sign -in data.json -signer cert.pem -inkey key.pem -outform DER -out data.sig | CMS 分离签名,接口报文签名常用 | |
openssl cms -verify -in data.sig -inform DER -CAfile ca.crt -out data.out | 校验 CMS 签名并输出原文 | |
openssl dgst -sha256 -sign ec.key -out sig.bin file.txt | ECDSA 签名,密钥短、速度快 | |
sha256sum file.txt | 系统自带摘要命令,与 openssl 结果应一致 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl x509 -in cert.pem -outform DER -out cert.der | PEM 证书转 DER 二进制 | |
openssl x509 -inform DER -in cert.der -outform PEM -out cert.pem | DER 证书转回 PEM | |
openssl pkey -in key.pem -outform DER -out key.der | 私钥转 DER | |
openssl pkey -in key.pem -pubout -outform DER -out pub.der | 公钥转 DER | |
openssl pkcs12 -export -in server.crt -inkey key.pem -out server.pfx -name "example.com" | 证书 + 私钥打包成 PFX,Windows/IIS 常用 | |
openssl pkcs12 -export -in server.crt -inkey key.pem -certfile chain.crt -out server.pfx | PFX 中带中间证书,避免客户端链不全 | |
openssl pkcs12 -export -in server.crt -inkey key.pem -out server.pfx -passout pass:123456 | 非交互指定导出密码,脚本化使用 | |
openssl pkcs12 -export -in server.crt -inkey key.pem -out server.pfx -legacy | 3.x 兼容老客户端,使用 3DES/RC2 加密 | |
openssl pkcs12 -in server.pfx -nodes -out all.pem | PFX 拆成明文私钥 + 证书,注意文件权限 | |
openssl pkcs12 -in server.pfx -nokeys -out cert.pem | 只导出证书部分 | |
openssl pkcs12 -in server.pfx -nocerts -nodes -out key.pem | 只导出私钥部分 | |
openssl pkcs12 -in server.pfx -info -noout | 只查看 PFX 结构、算法与别名 | |
openssl pkcs8 -topk8 -nocrypt -in key.pem -out key.pk8 | 私钥转 PKCS#8 明文格式 | |
openssl pkcs8 -topk8 -v2 aes-256-cbc -in key.pem -out key.pk8 | 私钥转 PKCS#8 并加密 | |
openssl rsa -in key.pem -traditional -out key_pkcs1.pem | RSA 私钥转回 PKCS#1 传统格式,老设备要求 | |
openssl pkcs7 -in bundle.p7b -print_certs -out certs.pem | 从 PKCS#7 中提取全部证书 | |
cat server.crt intermediate.crt > fullchain.pem | 合并证书链,顺序必须是站点证书在前 | |
cat ca.crt >> fullchain.pem | 按需追加根证书,部分客户端要求完整链 | |
openssl storeutl -noout -text -certs cert.pem | 按 URI 读取证书库对象,排查系统证书 | |
openssl asn1parse -in cert.der -inform DER -i | 查看 DER 结构,定位解析异常 | |
openssl x509 -in cert.pem -out cert.crt | .crt 与 .pem 只是后缀差异,内容格式才决定能否使用 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl s_client -connect example.com:443 -servername example.com | 最常用的握手测试,SNI 必须显式指定 | |
openssl s_client -connect example.com:443 -servername example.com -showcerts | 打印服务端下发的完整证书链 | |
openssl s_client -connect example.com:443 -servername example.com -brief | 3.x 精简输出,只看协议、加密套件与校验结果 | |
openssl s_client -connect example.com:443 -servername example.com -state | 打印握手每个阶段,定位卡在哪一步 | |
openssl s_client -connect example.com:443 -tls1_2 | 只测 TLS 1.2 是否可用 | |
openssl s_client -connect example.com:443 -tls1_3 | 只测 TLS 1.3 是否可用 | |
openssl s_client -connect example.com:443 -ciphersuites TLS_AES_256_GCM_SHA384 | TLS 1.3 指定套件,验证配置是否生效 | |
openssl s_client -connect example.com:443 -cipher ECDHE-RSA-AES128-GCM-SHA256 | TLS 1.2 指定套件测试 | |
openssl s_client -connect example.com:443 -servername example.com -alpn h2,http/1.1 | 查看 ALPN 协商结果,确认是否走 HTTP/2 | |
openssl s_client -connect example.com:443 -CAfile ca.crt -verify_return_error | 校验失败立即中断,脚本化巡检用 | |
openssl s_client -connect example.com:443 -cert client.crt -key client.key -CAfile ca.crt | mTLS 双向认证测试 | |
openssl s_client -connect mail.example.com:25 -starttls smtp | SMTP 明文端口升级 TLS 测试 | |
openssl s_client -connect mail.example.com:143 -starttls imap | IMAP 测试,另有 pop3、ftp、xmpp 等参数 | |
openssl s_client -connect db.example.com:5432 -starttls postgres | PostgreSQL 的 TLS 握手测试 | |
openssl s_client -connect db.example.com:3306 -starttls mysql | MySQL 的 TLS 握手测试 | |
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -dates -fingerprint -sha256 | 一条命令拿到线上证书主体、有效期与指纹 | |
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | awk '/BEGIN CERT/,/END CERT/' > chain.pem | 导出线上证书链做离线分析 | |
openssl s_client -connect old.example.com:443 -cipher "DEFAULT@SECLEVEL=1" -tls1_2 | 兼容老设备的低安全级别测试,仅排障用 | |
openssl s_client -connect example.com:443 -no_ssl2 -no_ssl3 | 显式禁用已淘汰协议,确认服务端是否仍开放 | |
openssl s_client -connect 127.0.0.1:443 -servername example.com | 本机直连 Nginx 校验配置,绕过 DNS 与负载均衡 | |
openssl ciphers -v "ECDHE+AESGCM:!aNULL:!MD5" | 预览密码套件列表,配置 ssl_ciphers 前先验证 | |
openssl s_server -accept 4433 -cert cert.pem -key key.pem -www | 本地起测试 TLS 服务,验证证书是否可用 | |
openssl s_time -connect example.com:443 -new -time 10 | 统计新建连接握手性能 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl enc -aes-256-cbc -pbkdf2 -iter 200000 -salt -in plain.txt -out plain.enc | AES-256-CBC 加密文件,必须带 pbkdf2 派生密钥 | |
openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -in plain.enc -out plain.txt | 解密文件,参数必须与加密时完全一致 | |
openssl enc -aes-256-cbc -pbkdf2 -md sha512 -salt -in plain.txt -out plain.enc | 指定 KDF 摘要,跨版本解密时必须一致 | |
openssl enc -aes-128-cbc -nosalt -K 00112233445566778899aabbccddeeff -iv 000102030405060708090a0b0c0d0e0f -in plain.txt -out plain.enc | 用固定 key/iv 加密,仅用于与程序对接 | |
openssl enc -base64 -in file.bin -out file.b64 | 文件转 Base64 | |
openssl enc -d -base64 -in file.b64 -out file.bin | Base64 还原二进制 | |
openssl base64 -in file.bin -out file.b64 | 等价的 Base64 子命令 | |
openssl base64 -d -A -in file.b64 -out file.bin | -A 单行输出,适配不支持换行的配置项 | |
openssl rand -hex 16 | 生成 16 字节随机数的十六进制串(32 字符) | |
openssl rand -base64 32 | 生成 32 字节随机数的 Base64 串,适合做密钥 | |
openssl rand -out key.bin 32 | 直接输出 32 字节随机二进制文件 | |
openssl passwd -6 -salt xyz "MyPassw0rd" | 生成 SHA-512 crypt 口令散列,Linux /etc/shadow 用 | |
openssl passwd -1 -salt xyz "MyPassw0rd" | 生成 MD5 crypt 散列,仅兼容老系统 | |
openssl passwd -apr1 "MyPassw0rd" | 生成 Apache htpasswd 的 apr1 散列 | |
openssl kdf -keylen 32 -kdfopt digest:SHA256 -kdfopt pass:secret -kdfopt hexsalt:00112233 HKDF | HKDF 派生密钥,与协议实现对齐时用 | |
openssl mac -digest SHA256 -macopt key:mysecret HMAC | 计算 HMAC,输入从标准输入读取 | |
echo -n "hello" | openssl dgst -sha256 | -n 避免换行参与计算,联调时最易踩的坑 | |
openssl enc -des-ede3-cbc -provider legacy -in plain.txt -out plain.enc | 3.x 使用 3DES 等旧算法需显式加载 legacy provider | |
umask 077 && openssl rand -out secret.key 32 | 生成密钥时收紧权限,避免被同组用户读取 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out example.key | 申请证书第一步:生成私钥并妥善备份 | |
openssl req -new -key example.key -out example.csr -subj "/C=CN/O=Example/CN=example.com" -addext "subjectAltName=DNS:example.com,DNS:www.example.com" | 第二步:生成带 SAN 的 CSR 提交给 CA | |
cat example.crt intermediate.crt > fullchain.pem | 第三步:把 CA 下发的证书与中间证书合并 | |
ssl_certificate /etc/nginx/ssl/fullchain.pem; | Nginx 配置:指向完整链 | |
ssl_certificate_key /etc/nginx/ssl/example.key; | Nginx 配置:指向私钥 | |
ssl_protocols TLSv1.2 TLSv1.3; | Nginx 配置:只保留安全协议版本 | |
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305; | Nginx 配置:收紧密码套件 | |
ssl_dhparam /etc/nginx/ssl/dhparam.pem; | Nginx 配置:RSA 密钥交换需要 DH 参数 | |
nginx -t && systemctl reload nginx | 改完证书先测语法再平滑重载 | |
keytool -importkeystore -srckeystore server.pfx -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS | PFX 转 JKS,Tomcat / Java 应用使用 | |
keytool -list -v -keystore keystore.jks | grep -A3 "Certificate chain" | 检查 JKS 中证书链是否完整 | |
openssl pkcs12 -export -in fullchain.pem -inkey example.key -out server.pfx -name tomcat | 生成 Tomcat 用的 PFX,别名与配置要对应 | |
openssl x509 -in example.crt -noout -checkend 604800 || echo "证书 7 天内到期" | 巡检脚本:临期告警 | |
for h in a.example.com b.example.com; do echo | openssl s_client -connect $h:443 -servername $h 2>/dev/null | openssl x509 -noout -enddate; done | 批量检查多域名证书到期时间 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
openssl speed -evp aes-256-gcm | 测试 AES-GCM 吞吐,评估加密对带宽的影响 | |
openssl speed -evp chacha20-poly1305 | 测试 ChaCha20 性能,无 AES 指令集时更优 | |
openssl speed rsa2048 | 测试 RSA 2048 签名与验签速度 | |
openssl speed -multi 4 ecdsap256 | 多核并行测试 ECDSA 性能 | |
openssl s_time -connect example.com:443 -new -time 10 | 测量 TLS 握手 QPS | |
openssl errstr 0A000126 | 把错误码翻译成可读原因,日志排查用 | |
openssl asn1parse -in cert.pem -i | 解析 PEM 内部 ASN.1 结构 | |
openssl rehash /etc/ssl/certs | 重建证书目录的 hash 链接,-CApath 校验失效时用 | |
openssl x509 -in cert.pem -noout -text | grep -E "Not (Before|After)|Subject:|Issuer:" | 快速抓关键信息,适合贴进工单 | |
openssl list -providers -verbose | 查看 provider 属性,排查 3.x 算法缺失 | |
strace -f -e trace=openat openssl s_client -connect example.com:443 2>&1 | grep -i cert | 跟踪证书文件读取路径,定位 CA 目录问题 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
unable to load certificate | 路径错误或文件不是 PEM,DER 需加 -inform DER | |
Expecting: TRUSTED CERTIFICATE | 文件里混入了非证书内容,常见于把私钥和证书拼在一起 | |
no start line | 文件不是 PEM 格式,或开头缺少 -----BEGIN 行 | |
certificate has expired | 证书已过期,用 x509 -noout -dates 确认 | |
certificate is not yet valid | 服务器时间不准或证书尚未生效,先校时 | |
unable to get local issuer certificate(num=20) | 缺中间证书,服务端要下发完整链 | |
self-signed certificate(num=18) | 用了自签证书但客户端未信任其根 CA | |
self-signed certificate in certificate chain | 链中混入自签根,客户端不认,去掉根证书重试 | |
unable to verify the first certificate | 服务端只发站点证书,未附中间证书 | |
key values mismatch | 证书与私钥不配对,比对两者 modulus 摘要 | |
wrong version number | 明文端口用了 TLS,或代理把 HTTPS 转成了 HTTP | |
no peer certificate available | SNI 未指定或服务端未配置该域名证书 | |
sslv3 alert handshake failure | 密码套件不匹配,或客户端协议版本被服务端禁用 | |
no suitable key share | TLS 1.3 密钥交换组不兼容,检查 curves 配置 | |
tlsv1 alert unknown ca | mTLS 场景客户端证书不被服务端信任 | |
bad decrypt | 口令错误,或加解密参数(算法/KDF/iter)不一致 | |
bad password read | 交互输入口令失败,脚本中改用 -passin pass:xxx | |
unable to load Private Key | 私钥格式不符(PKCS#1 与 PKCS#8)或口令错误 | |
digital envelope routines::unsupported | 3.x 默认禁用 MD4/DES 等旧算法,需 -provider legacy | |
dh key too small / ee key too small | 密钥长度低于安全级别,提升到 2048 位或调 SECLEVEL | |
certificate verify failed | 链、有效期、域名任一不满足,先用 verify 定位 | |
write:errno=104 / Connection reset by peer | 被防火墙或 WAF 拦截,或后端未监听该端口 | |
unable to find eof | 输入流提前结束,检查管道与重定向是否给了空内容 | |
errno=10054(Windows) | 对端强制关闭连接,多为协议版本或证书不被接受 |
运维常用组合
genpkey 生成 ca.key → req -x509 生成 ca.crt(带 CA:TRUE)→ 生成站点私钥与 CSR → x509 -req -CA 签发 → verify 校验 → 部署 fullchaingenpkey 生成私钥 → req -new -addext SAN 生成 CSR → 提交 CA → 下载证书与中间证书 → cat 合并 fullchain.pem → nginx -t 重载openssl s_client -connect host:443 -servername host -showcerts → 看证书链是否完整 → x509 -noout -dates 查有效期 → verify 定位缺失层级x509 -noout -checkend 604800 判断临期 → s_client 拉线上证书 → for 循环批量检查多域名 → 输出到期时间并告警pkcs12 -in server.pfx -nodes -out all.pem → 拆出 cert.pem 与 key.pem → cat 证书 + 中间证书 → 配置 ssl_certificate 与 ssl_certificate_keyrand -out key.bin 32 生成密钥 → enc -aes-256-cbc -pbkdf2 加密 → 密钥单独保管 → 解密时参数完全一致实战要点
1. SAN 是唯一硬指标
现代浏览器与 Java 客户端只认 subjectAltName,CN 已不再参与域名匹配,签发时必须带 SAN
2. 证书链顺序不能错
fullchain 必须是站点证书 → 中间证书 → 根证书,顺序颠倒会直接握手失败
3. 私钥 600 且不进仓库
私钥文件权限设为 600,禁止提交到 Git,生产环境交给 KMS 或密钥管理平台
4. 加解密参数要成对
enc 的算法、KDF、迭代次数、摘要必须与解密端一致,缺一项就报 bad decrypt
5. s_client 必须带 SNI
不加 -servername 会拿到默认站点证书,多域名场景下极易误判
6. 3.x 旧算法要 legacy
OpenSSL 3 默认不加载 MD4、DES、RC4,测试老系统时加 -provider legacy 或 default
相关工具
Linux命令速查
文件、文本、权限、进程、网络、磁盘、systemd与防火墙等 Linux 常用命令速查手册
Docker命令速查
镜像、容器、网络、数据卷、Compose、Swarm、清理与排障等 Docker 常用命令速查手册
Nginx命令速查
服务管理、配置指令、反向代理、HTTPS、限流缓存、日志排查等 Nginx 常用命令速查手册
K8S命令速查
集群上下文、Pod调试、工作负载、Service与Ingress、存储、权限、排障等 kubectl 常用命令速查手册
Windows CMD命令速查
文件目录、网络诊断、进程服务、系统信息、用户权限、注册表、批处理等 Windows CMD 常用命令速查手册
systemctl服务管理速查
服务启停、开机自启、unit文件编写、日志查看、定时器、依赖分析与排障等 systemctl 命令速查手册
关于OpenSSL命令速查
在线 OpenSSL 命令速查手册,按版本与环境、密钥生成与管理、CSR 与自签名证书、证书签发与校验、签名验签与摘要、格式转换 PEM/DER/PKCS12、TLS 连接测试 s_client、证书链与 OCSP 校验、加解密与随机数、性能测试与常见报错排查等 11 类场景整理 200 条常用命令与配置片段,每条附中文说明与可直接复制的写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 openssl version -a 与 list -digest-algorithms/-cipher-algorithms/-providers 与 help、genpkey -algorithm RSA|EC|ED25519 与 rsa_keygen_bits/ec_paramgen_curve 与 genrsa 与 ecparam -name prime256v1 与 pkey -pubout/-text/-aes256 与 rsa -check、req -new 与 -newkey rsa:2048 -nodes 与 -subj 与 -addext subjectAltName 与 -config 与 req -in -noout -text -verify 与 -nameopt RFC2253、req -x509 自签根 CA 与 basicConstraints/keyUsage 与 x509 -noout -text/-dates/-subject/-issuer/-serial/-fingerprint -sha256/-pubkey/-ext subjectAltName/-checkend、x509 -req -CA -CAkey -CAcreateserial -extfile -extensions -copy_extensions、verify -CAfile/-untrusted/-CApath 与 dgst -sha256 -sign/-verify 与 pkeyutl -sign -rawin -digest、x509 -outform DER 与 pkcs12 -export/-nodes/-nokeys/-nocerts 与 pkcs8 -topk8 -nocrypt/-v2 与 pkcs7 -print_certs、s_client -connect -servername -showcerts -state -brief -tls1_2/-tls1_3 -alpn -cipher -ciphersuites -CAfile -cert/-key 与 -starttls smtp/imap/pop3/postgres/mysql 与 s_server -www 与 s_time 与 ocsp -issuer -cert -url 与 crl -text、enc -aes-256-cbc -pbkdf2 -iter -salt/-d -base64 与 rand -hex/-base64 与 passwd -6/-1/-apr1 与 speed -evp 与 asn1parse 与 rehash,以及 unable to load certificate、certificate has expired、unable to get local issuer certificate、self-signed certificate、key values mismatch、wrong version number、no peer certificate available、sslv3 alert handshake failure、bad decrypt、digital envelope routines::unsupported 等报错排查。适用于 HTTPS 证书申请与部署、内网自建 CA 与 mTLS 双向认证、证书格式转换与 PFX 导入导出、TLS 握手与证书链故障定位、数据加解密与签名验签、密钥与合规审计,以及运维与安全工程师面试复习。
核心能力
- 涵盖 openssl version -a 与 list -digest-algorithms/-cipher-algorithms/-providers 与 help、genpkey -algorithm RSA|EC|ED25519 与 rsa_keygen_bits/ec_paramgen_curve 与 genrsa 与 ecparam -name prime256v1 与 pkey -pubout/-text/-aes256 与 rsa -check、req -new 与 -newkey rsa:2048 -nodes 与 -subj 与 -addext subjectAltName 与 -config 与 req -in -noout -text -verify 与 -nameopt RFC2253、req -x509 自签根 CA 与 basicConstraints/keyUsage 与 x509 -noout -text/-dates/-subject/-issuer/-serial/-fingerprint -sha256/-pubkey/-ext subjectAltName/-checkend、x509 -req -CA -CAkey -CAcreateserial -extfile -extensions -copy_extensions、verify -CAfile/-untrusted/-CApath 与 dgst -sha256 -sign/-verify 与 pkeyutl -sign -rawin -digest、x509 -outform DER 与 pkcs12 -export/-nodes/-nokeys/-nocerts 与 pkcs8 -topk8 -nocrypt/-v2 与 pkcs7 -print_certs、s_client -connect -servername -showcerts -state -brief -tls1_2/-tls1_3 -alpn -cipher -ciphersuites -CAfile -cert/-key 与 -starttls smtp/imap/pop3/postgres/mysql 与 s_server -www 与 s_time 与 ocsp -issuer -cert -url 与 crl -text、enc -aes-256-cbc -pbkdf2 -iter -salt/-d -base64 与 rand -hex/-base64 与 passwd -6/-1/-apr1 与 speed -evp 与 asn1parse 与 rehash,以及 unable to load certificate、certificate has expired、unable to get local issuer certificate、self-signed certificate、key values mismatch、wrong version number、no peer certificate available、sslv3 alert handshake failure、bad decrypt、digital envelope routines::unsupported 等报错排查
适用场景
适用于 HTTPS 证书申请与部署、内网自建 CA 与 mTLS 双向认证、证书格式转换与 PFX 导入导出、TLS 握手与证书链故障定位、数据加解密与签名验签、密钥与合规审计,以及运维与安全工程师面试复习。OpenSSL命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。
常见问题
- OpenSSL命令速查是免费的吗?需要注册或安装吗?
- OpenSSL命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
- OpenSSL命令速查支持哪些功能?
- 涵盖 openssl version -a 与 list -digest-algorithms/-cipher-algorithms/-providers 与 help、genpkey -algorithm RSA|EC|ED25519 与 rsa_keygen_bits/ec_paramgen_curve 与 genrsa 与 ecparam -name prime256v1 与 pkey -pubout/-text/-aes256 与 rsa -check、req -new 与 -newkey rsa:2048 -nodes 与 -subj 与 -addext subjectAltName 与 -config 与 req -in -noout -text -verify 与 -nameopt RFC2253、req -x509 自签根 CA 与 basicConstraints/keyUsage 与 x509 -noout -text/-dates/-subject/-issuer/-serial/-fingerprint -sha256/-pubkey/-ext subjectAltName/-checkend、x509 -req -CA -CAkey -CAcreateserial -extfile -extensions -copy_extensions、verify -CAfile/-untrusted/-CApath 与 dgst -sha256 -sign/-verify 与 pkeyutl -sign -rawin -digest、x509 -outform DER 与 pkcs12 -export/-nodes/-nokeys/-nocerts 与 pkcs8 -topk8 -nocrypt/-v2 与 pkcs7 -print_certs、s_client -connect -servername -showcerts -state -brief -tls1_2/-tls1_3 -alpn -cipher -ciphersuites -CAfile -cert/-key 与 -starttls smtp/imap/pop3/postgres/mysql 与 s_server -www 与 s_time 与 ocsp -issuer -cert -url 与 crl -text、enc -aes-256-cbc -pbkdf2 -iter -salt/-d -base64 与 rand -hex/-base64 与 passwd -6/-1/-apr1 与 speed -evp 与 asn1parse 与 rehash,以及 unable to load certificate、certificate has expired、unable to get local issuer certificate、self-signed certificate、key values mismatch、wrong version number、no peer certificate available、sslv3 alert handshake failure、bad decrypt、digital envelope routines::unsupported 等报错排查。
- OpenSSL命令速查适合哪些场景使用?
- 适用于 HTTPS 证书申请与部署、内网自建 CA 与 mTLS 双向认证、证书格式转换与 PFX 导入导出、TLS 握手与证书链故障定位、数据加解密与签名验签、密钥与合规审计,以及运维与安全工程师面试复习。