openssl生成https證書

2021-05-01 04:41:20 字數 2936 閱讀 2886

openssl生成https證書

1.首先要生成伺服器端的私鑰(key檔案):

openssl genrsa -des3 -out server.key 1024

執行時會提示輸入密碼,此密碼用於加密key檔案

去除key檔案口令的命令:

openssl rsa -in server.key -out server.key

2.openssl req -new -key server.key -out server.csr -config openssl.cnf

生成certificate signing request(csr),生成的csr檔案交給ca簽名後形成服務端自己的證書.螢幕上將有提示,依照其指示一步一步輸入要求的個人資訊即可.

3.對客戶端也作同樣的命令生成key及csr檔案:

openssl genrsa -des3 -out client.key 1024

openssl req -new -key client.key -out client.csr -config openssl.cnf

4.csr檔案必須有ca的簽名才可形成證書.可將此檔案傳送到verisign等地方由它驗證.自己生成:

openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf

5.用生成的ca的證書為剛才生成的server.csr,client.csr檔案簽名:

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

注意: 此時會出錯:using configuration from /usr/share/ssl/openssl.cnf i am unable to access the ./democa/newcerts directory ./democa/newcerts: no such file or directory

解決方法: 1).mkdir -p ./democa/newcerts

2).touch democa/index.txt

3).touch democa/serial

4).echo 01 > democa/serial

6.合併證書檔案(crt)和私鑰檔案(key)

1).cat client.crt client.key > client.pem

2).cat server.crt server.key > server.pem

7.合併成pfx證書

1).openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12

2).openssl pkcs12 -export -clcerts -in server.crt -inkey server.key -out server.p12

8.文字化證書

1).openssl pkcs12 -in client.p12 -out client.txt

2).openssl pkcs12 -in server.p12 -out server.txt

9.螢幕模式顯式:(證書、私鑰、公鑰)

1).openssl x509 -in client.crt -noout -text -modulus

2).openssl rsa -in server.key -noout -text -modulus

3).openssl rsa -in server.pub -noout -text -modulus

10.得到dh

1).openssl dhparam -out dh1024.pem 1024

(8) 編輯apache的配置檔案httpd.conf

開啟: loadmodule ssl_module modules/mod_ssl.so

去掉以下語句的注釋, include conf/extra/httpd-ssl.conf

(9) 編輯 conf/extra/httpd-ssl.conf

sslengine on

sslcertificatefile conf/ssl/server.crt

sslcertificatekeyfile conf/ssl/server.key

sslcertificatechainfile conf/ssl/ca.crt

cd /usr/local/apache/conf

openssl genrsa -des3 -out server.key 1024

openssl req -new -key server.key -out server.csr -config /usr/local/ssl/openssl.cnf

openssl req -new -x509 -keyout ca.key -out ca.crt -config /usr/local/ssl/openssl.cnf

mkdir -p ./democa/newcerts

touch democa/index.txt

touch democa/serial

echo 01 > democa/serial

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config /usr/local/ssl/openssl.cnf

bin/apachectl start

openssl生成https證書

本文主要介紹在linux環境下通過openssl生成自己的ssl證書,並搭配nginx伺服器啟用https。我對證書的了解也不是很多,從網上蒐羅一些資料,並在centos上成功搭建https伺服器,通過本文整理如下 etc pki ca index.txt 跟蹤已頒發的證書,初始為空。注意是0位元組...

openssl生成https證書

1.首先要生成伺服器端的私鑰 key檔案 openssl genrsa des3 out server.key 1024 執行時會提示輸入密碼,此密碼用於加密key檔案 去除key檔案口令的命令 openssl rsa in server.key out server.key 2.openssl r...

openssl生成https證書

本文主要介紹在linux環境下通過openssl生成自己的ssl證書,並搭配nginx伺服器啟用https。我對證書的了解也不是很多,從網上蒐羅一些資料,並在centos上成功搭建https伺服器,通過本文整理如下 etc pki ca index.txt 跟蹤已頒發的證書,初始為空。注意是0位元組...