OpenSSL是一个健壮的、商业级的、功能齐全的工具包,用于通用加密和安全通信。
通过 OpenSSL 工具生成自签名证书
# Generate CA private key
openssl genrsa -out ca.key 2048
# Generate CSR
openssl req -new -key ca.key -out ca.csr
# Generate Self Signed certificate(CA 根证书)
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
具体的执行过程如下:
[root@localhost ~]# mkdir ssl
[root@localhost ~]# cd ssl/
[root@localhost ssl]#
[root@localhost ssl]# openssl genrsa -out ca.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
.....................................................................+++++
.......................................................................................................................................................................................................................................................+++++
e is 65537 (0x010001)
[root@localhost ssl]#
[root@localhost ssl]# ll
总用量 4
-rw------- 1 root root 1675 5月 14 12:01 ca.key
[root@localhost ssl]#
[root@localhost ssl]# openssl req -new -key ca.key -out ca.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) [XX]:CN
State or Province Name (full name) []:Shanghai
Locality Name (eg, city) [Default City]:Shanghai
Organization Name (eg, company) [Default Company Ltd]:DevOps
Organizational Unit Name (eg, section) []:DevOps
Common Name (eg, your name or your server's hostname) []:DevOps
Email Address []:devops@devops.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:devops
An optional company name []:devops
[root@localhost ssl]#
[root@localhost ssl]# ll
总用量 8
-rw-r--r-- 1 root root 1110 5月 14 12:04 ca.csr
-rw------- 1 root root 1675 5月 14 12:01 ca.key
[root@localhost ssl]#
[root@localhost ssl]# openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
Signature ok
subject=C = CN, ST = Shanghai, L = Shanghai, O = DevOps, OU = DevOps, CN = DevOps, emailAddress = devops@devops.com
Getting Private key
[root@localhost ssl]#
[root@localhost ssl]# ll
总用量 12
-rw-r--r-- 1 root root 1310 5月 14 12:06 ca.crt
-rw-r--r-- 1 root root 1110 5月 14 12:04 ca.csr
-rw------- 1 root root 1675 5月 14 12:01 ca.key
[root@localhost ssl]#
如果是通过 IP 地址访问 HTTPS 服务,红框内的部分请填写 IP 地址,比如 127.0.0.1,如果通过域名访问,可以将其设置为域名:
网友评论