GeekIt

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.pemRSA 专用导出公钥,与 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.comsan.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 copy3.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.crt3.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.txtHMAC 计算,接口签名联调常用
openssl pkeyutl -sign -inkey key.pem -rawin -digest sha256 -in file.txt -out sig.bin3.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.encRSA 公钥加密小数据(受密钥长度限制)
openssl pkeyutl -decrypt -inkey key.pem -in secret.enc -out secret.txtRSA 私钥解密
openssl smime -sign -in msg.txt -signer cert.pem -inkey key.pem -out signed.p7mS/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.sigCMS 分离签名,接口报文签名常用
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.txtECDSA 签名,密钥短、速度快
sha256sum file.txt系统自带摘要命令,与 openssl 结果应一致
命令 / 片段说明复制
openssl x509 -in cert.pem -outform DER -out cert.derPEM 证书转 DER 二进制
openssl x509 -inform DER -in cert.der -outform PEM -out cert.pemDER 证书转回 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.pfxPFX 中带中间证书,避免客户端链不全
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 -legacy3.x 兼容老客户端,使用 3DES/RC2 加密
openssl pkcs12 -in server.pfx -nodes -out all.pemPFX 拆成明文私钥 + 证书,注意文件权限
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.pemRSA 私钥转回 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 -brief3.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_SHA384TLS 1.3 指定套件,验证配置是否生效
openssl s_client -connect example.com:443 -cipher ECDHE-RSA-AES128-GCM-SHA256TLS 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.crtmTLS 双向认证测试
openssl s_client -connect mail.example.com:25 -starttls smtpSMTP 明文端口升级 TLS 测试
openssl s_client -connect mail.example.com:143 -starttls imapIMAP 测试,另有 pop3、ftp、xmpp 等参数
openssl s_client -connect db.example.com:5432 -starttls postgresPostgreSQL 的 TLS 握手测试
openssl s_client -connect db.example.com:3306 -starttls mysqlMySQL 的 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.encAES-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.binBase64 还原二进制
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 HKDFHKDF 派生密钥,与协议实现对齐时用
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.enc3.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 JKSPFX 转 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 availableSNI 未指定或服务端未配置该域名证书
sslv3 alert handshake failure密码套件不匹配,或客户端协议版本被服务端禁用
no suitable key shareTLS 1.3 密钥交换组不兼容,检查 curves 配置
tlsv1 alert unknown camTLS 场景客户端证书不被服务端信任
bad decrypt口令错误,或加解密参数(算法/KDF/iter)不一致
bad password read交互输入口令失败,脚本中改用 -passin pass:xxx
unable to load Private Key私钥格式不符(PKCS#1 与 PKCS#8)或口令错误
digital envelope routines::unsupported3.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)对端强制关闭连接,多为协议版本或证书不被接受

运维常用组合

内网自建 CAgenpkey 生成 ca.key → req -x509 生成 ca.crt(带 CA:TRUE)→ 生成站点私钥与 CSR → x509 -req -CA 签发 → verify 校验 → 部署 fullchain
公有 CA 申请genpkey 生成私钥 → 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 循环批量检查多域名 → 输出到期时间并告警
PFX 转 Nginxpkcs12 -in server.pfx -nodes -out all.pem → 拆出 cert.pem 与 key.pem → cat 证书 + 中间证书 → 配置 ssl_certificate 与 ssl_certificate_key
敏感文件加密备份rand -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

共 206 条 OpenSSL 命令 · 示例中的域名、路径与密钥文件名请替换为实际环境

关于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 握手与证书链故障定位、数据加解密与签名验签、密钥与合规审计,以及运维与安全工程师面试复习。