openssl常用操作
参考:https://www.golinuxcloud.com/openssl-view-certificate/
查看证书信息
openssl x509 -in server.crt -text -noout
单个域名证书签发:
openssl genrsa -out ca.key 2048 #生成CA的私钥 openssl req -new -key ca.key -out ca.csr #生成CA的证书签署请求 openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt #生成CA的自签证书 openssl genrsa -out front-envoy.key 2048 #生成front-envoy私钥 openssl req -new -key front-envoy.key -out front-envoy.csr #生成front-envoy的证书签署请求 openssl x509 -req -days 365 -in front-envoy.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out front-envoy.crt #使用CA的证书和私钥签发front-envoy证书 openssl x509 -noout -modulus -in front-envoy.crt | openssl md5 #检查签发的证书和私钥是否匹配 openssl rsa -noout -modulus -in front-envoy.key | openssl md5 #检查签发的证书和私钥是否匹配
SAN证书签发(支持多个域名):
1、CA自签证书: openssl genrsa -out ca.key 2048 openssl req -new -key ca.key -out ca.csr openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt -days 3650 -sha256 2.为SAN证书创建配置文件,注意alt_name cat server_cert.cnf [req] distinguished_name = req_distinguished_name req_extensions = req_ext prompt = no [req_distinguished_name] C = CN ST = Sichuan L = Chengdu O = myland OU = myland CN = ban21.myland.com [req_ext] subjectAltName = @alt_names [alt_names] DNS.1=myland.com DNS.2=harbor.myland.com 3、生成server证书签署请求 openssl genrsa -out server.key 2048 openssl req -new -key server.key -out server.csr -config server_cert.cnf 4、#签发证书 openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt #检查公私钥是否匹配 openssl x509 -noout -modulus -in server.crt | openssl md5 openssl rsa -noout -modulus -in server.key | openssl md5