使用openssl生成自簽名證書
- 1. 交互式生成
- 2. 一步生成
- 參考
1. 交互式生成
自簽名 SSL 證書的生成涉及一個簡單的 3 步過程:
步驟 1:創建服務器私鑰
openssl genrsa -out cert.key 2048
步驟 2:創建證書簽名請求 (CSR)
openssl req -new -key cert.key -out cert.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:BJ
Locality Name (eg, city) []:BJ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:TM
Organizational Unit Name (eg, section) []:TM
Common Name (e.g. server FQDN or YOUR name) []:tm.com
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
步驟 3:使用私鑰和 CSR 簽署證書
openssl x509 -req -days 3650 -in cert.csr -signkey cert.key -out cert.crt
Certificate request self-signature ok
subject=C=CN, ST=BJ, L=BJ, O=TM, OU=TM, CN=tm.com
恭喜!您現在擁有有效期為 10 年的自簽名 SSL 證書。
2. 一步生成
openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 \-subj "/C=CN/ST=BJ/L=BJ/O=TM/OU=TM/CN=tm.com" \-keyout cert.key -out cert.crt
參考
Generation of a Self Signed Certificate