温馨提示×

linux openssl如何生成csr

小樊
38
2026-09-25 19:53:59
栏目: 云计算

在 Linux 下使用 OpenSSL 生成 CSR(证书签名请求) 通常步骤如下:


一、生成私钥 + CSR(最常用)

openssl req -new -newkey rsa:2048 -nodes \
-keyout domain.key -out domain.csr

参数说明:

  • rsa:2048:生成 2048 位 RSA 私钥
  • -nodes:不加密私钥(否则每次使用都要输密码)
  • -keyout:私钥文件
  • -out:CSR 文件

执行后会提示输入信息:

Country Name (2 letter code): CN
State or Province Name: Beijing
Locality Name: Beijing
Organization Name: Your Company
Organizational Unit Name: IT
Common Name: www.example.com
Email Address:

二、已有私钥,只生成 CSR

openssl req -new -key domain.key -out domain.csr

三、使用配置文件生成 CSR(推荐生产环境)

openssl req -new -key domain.key -out domain.csr -config san.cnf

示例 san.cnf:

[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req

[req_distinguished_name]
CN = www.example.com

[v3_req]
subjectAltName = @alt_names

[alt_names]
DNS.1 = www.example.com
DNS.2 = example.com

四、查看 CSR 内容

openssl req -in domain.csr -noout -text

五、生成 ECC 私钥 + CSR(可选)

openssl ecparam -genkey -name prime256v1 -noout -out domain.key
openssl req -new -key domain.key -out domain.csr

如果你是 Nginx / Apache / 泛域名 / 多域名证书,可以告诉我使用场景,我可以给你更精确的命令。

0 踩