openssl自签ssl证书

警告
本文最后更新于 2023-01-05,文中内容可能已过时。

摘要

生成RSA私钥

1
openssl genrsa -out private.key 4096

生成 KEY 私钥和 CSR 证书签名请求文件

1
2
openssl req -new -key private.key -out custom.csr
openssl req -new -sha512 -nodes -newkey rsa:4096 -keyout bwcxtech.com.key -subj "/C=CN/O=bwcx/CN=bwcxtech.com" -out bwcxtech.com.csr

Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN

State or Province Name (full name) [Some-State]:ShangHai ← 省的全名,拼音

Locality Name (eg, city) []:Shanghai ← 市的全名,拼音

Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名

Organizational Unit Name (eg, section) []: ← 可以不输入

Common Name (eg, YOUR name) []: ← 此时不输入

Email Address []:1624717079@qq.com ← 电子邮箱,可随意填

Please enter the following ‘extra’ attributes

to be sent with your certificate request

A challenge password []: ← 可以不输入

An optional company name []: ← 可以不输入

以上命令生成时候要填很多东西 一个个看着写吧(可以随便,毕竟这是自己生成的证书)

https://img.bwcxtech.com/img/20200928164254.jpeg

其中有个要求输入密码,我这里没有输入,输入了密码后面使用需要填写密码才可以使用。

创建访问证书

openssl x509

1
2
3
openssl x509 -req -sha512 -in bwcxtech.com.csr -signkey bwcxtech.com.key -out bwcxtech.com.crt -days 3650
# v3版本
openssl x509 -req -sha512 -extfile /etc/pki/tls/openssl.cnf -extensions v3_req  -in bwcxtech.com.csr -out bwcxtech.com.crt -signkey bwcxtech.com.key -days 3650

openssl req

1
openssl req -x509 -sha512 -in bwcxtech.com.csr -key bwcxtech.com.key -out bwcxtech.com.crt -days 3650

这里365是证书有效期 推荐3650。这个大家随意。最后使用到的文件是key和crt文件。

  • 生成RSA私钥
1
openssl genrsa -out private.key 4096
  • 生成证书
1
openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/O=bwcx/CN=bwcxtech.com" -key private.key -out bwcxtech.com.crt

相关内容