1. 程式人生 > >創建CA自簽證書

創建CA自簽證書

ech data- city lease ber after .cn cal match

創建CA自簽證書

1,創建CA服務器的私鑰:

(umask 0077;openssl genrsa -out cakey.pem 2048)

註意:將私鑰放在目錄下

/etc/pki/CA/private

2,創建CA服務器自簽證書:

[[email protected] CA]# openssl req -new -x509 -key cakey.pem -out /etc/pki/CA/cacert.pem
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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:liubin
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server‘s hostname) []:www1.stu12.com
Email Address []:

3,創建文件:

[root@localhost CA]# touch index.txt
[root@localhost CA]# echo 01 > serial

4,創建服務器私鑰:
創建存放私鑰和證書位置:

mkdir -pv /www/html/ssl
[root@localhost /www/ssl]#(umask 0077;openssl genrsa -out httpd_key.pem)

5,創建服務器自簽證書:

[[email protected] /www/ssl]#openssl req -new -key httpd_key.pem -out httpd_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) []:BeiJing
Locality Name (eg, city) [Default City]:BeiJing
Organization Name (eg, company) [Default Company Ltd]:liubin
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server‘s hostname) []:www1.stu12.com
Email Address []:

Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

6,將服務器的證書傳送到CA服務器上:

scp httpd_csr root@172.16.12.21:/root

7,在CA服務器上對證書進行簽署:

[[email protected] CA]# openssl ca -in httpd_csr -out httpd_crt.pem
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jun  1 21:04:37 2017 GMT
            Not After : Jun  1 21:04:37 2018 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = BeiJing
            organizationName          = liubin
            organizationalUnitName    = ops
            commonName                = www1.stu12.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                51:B2:FC:C3:77:C2:CB:A1:4A:43:53:EA:D9:F8:C8:83:0A:59:91:41
            X509v3 Authority Key Identifier: 
                keyid:F3:0E:EB:57:25:77:45:EC:98:41:8F:D1:54:A9:DA:4C:9C:FA:04:3D

Certificate is to be certified until Jun  1 21:04:37 2018 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

8,將證書傳回服務器:

scp httpd_crt.pem root@172.16.12.11:/www/ssl/

9,在服務器安裝ssl模塊:

yum -y install mod_ssl

10修改ssl配置文件:

SSLCertificateFile /www/ssl/httpd_crt.pem
SSLCertificateKeyFile /www/ssl/httpd_key.pem

創建CA自簽證書