1. 程式人生 > >實驗:CentOS下構建私有CA

實驗:CentOS下構建私有CA

email quest wing echo ani tmp owin cit code

一、建立一CA頒發主機(機構)
1、生成私鑰;2、自簽證書

[root@www1 ~]# (umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)
Generating RSA private key, 4096 bit long modulus
..............................++
....++
e is 65537 (0x10001)

[root@www1 ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out
/etc/pki/CA/cacert.pem -days 360

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GuangXi
Locality Name (eg, city) [Default City]:GuiLin
Organization Name (eg, company) [Default Company Ltd]:jinglin
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server‘s hostname) []:ca.jinglin.com


Email Address []:[email protected] #可留空
[root@www1 ~]# ls /etc/pki/CA/
cacert.pem certs crl newcerts private
[root@www1 ~]# touch /etc/pki/CA/{serial,index.txt} #為CA提供所需的目錄及文件
[root@www1 ~]# echo 01 > /etc/pki/CA/serial

二、向CA主機請求簽署證書
1、生成私鑰;2、生成證書簽署請求,3、將請求(通過可靠方式)發送給CA主機;4、CA主機簽署證書

[root@localhost httpd]# mkdir ssl #以httpd為例,創建一目錄,

[root@localhost httpd]# cd ssl/
[root@localhost ssl]# (umask 077; openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
.+++
...............+++
e is 65537 (0x10001)

[root@localhost ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:GuangXi
Locality Name (eg, city) [Default City]:GuiLin
Organization Name (eg, company) [Default Company Ltd]:jinglin
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server‘s hostname) []:www.jinglin.com
Email Address []:[email protected]

Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:123456
[root@localhost ssl]# scp httpd.csr [email protected]:/tmp/

[root@www1 ~]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
[root@www1 ~]# cd /etc/pki/CA/
[root@www1 CA]# cat index.txt
V 190802095707Z 01 unknown /C=CN/ST=GuangXi/O=jinglin/OU=ca.jinglin.com/CN=www.jinglin.org/[email protected]
[root@www1 CA]# scp certs/httpd.crt [email protected]:/etc/httpd/ssl/ #簽完後發回,然後刪除兩臺主機上的httpd.csr

[root@localhost ssl]# openssl x509 -in httpd.crt -noout -serial -subject #查看證書信息
serial=01
subject= /C=CN/ST=GuangXi/O=jinglin/OU=ca.jinglin.com/CN=www.jinglin.org/[email protected]

私有CA構建完成

實驗:CentOS下構建私有CA