生成证书签名请求(Certificate Signing Request),用于向 CA 机构申请 SSL 证书。
# 生成 RSA 私钥和 CSR openssl req -new -newkey rsa:2048 -nodes -keyout private.key -out request.csr # 生成 ECC 私钥和 CSR openssl ecparam -genkey -name prime256v1 -out private.key openssl req -new -key private.key -out request.csr # 使用配置文件生成带 SAN 扩展的 CSR openssl req -new -config san.cnf -keyout private.key -out request.csr # 查看 CSR 信息 openssl req -in request.csr -text -noout # 验证 CSR openssl req -verify -in request.csr -text -noout # 从现有私钥生成 CSR openssl req -new -key private.key -out request.csr # 使用特定的签名算法 openssl req -new -sha256 -key private.key -out request.csr # SAN 配置文件示例 (san.cnf): [req] distinguished_name = req_distinguished_name req_extensions = v3_req prompt = no [req_distinguished_name] CN = example.com O = Example Inc OU = IT Department C = CN ST = Beijing L = Beijing [v3_req] basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [alt_names] DNS.1 = example.com DNS.2 = www.example.com DNS.3 = *.example.com