2019年9月2日 星期一

centos7 openSSL 教學

網路中文文章:  https://wiki.net-chinese.com.tw/sites/wiki.net-chinese.taipei/files/public_files/application/SSL%E6%86%91%E8%AD%89%E7%B0%A1%E6%98%93%E6%95%99%E5%AD%B8(Linux%20Apache).pdf


1.安裝openssl
sudo yum -y install perl perl-devel gcc gcc-c++ openssl version 

2.產出key 打入密碼,操作完畢後即產生 PEM 格式的「私鑰」檔案,檔名為 server.key,請保存好這份檔案

 openssl genrsa -des3 -out server.key 2048

 3.產生 CSR 文件(Certificate Signing Request)

openssl req -new -key server.key -out certreq.txt

 產生填入資料參考網路中文範例 https://wiki.net-chinese.com.tw/sites/wiki.net-chinese.taipei/files/public_files/application/SSL%E6%86%91%E8%AD%89%E7%B0%A1%E6%98%93%E6%95%99%E5%AD%B8(Linux%20Apache).pdf


 4.Apache 安裝ssl憑證模組
yum -y install httpd mod_ssl

sudo systemctl enable httpd.service

systemctl start httpd.service 


5.拿到的SSL憑證放在 centos7的目錄下

mkdir -p /etc/ssl/private
chmod 777 /etc/ssl/private 


6.設定 sudo vi /etc/httpd/conf.d/ssl.conf

 <VirtualHost *:443>
 DocumentRoot /var/www/html
 ServerName www.example.com
 SSLEngine on
SSLCertificateFile /etc/ssl/private/certificate.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
 </VirtualHost> 

調整文件名以匹配您的證書文件: SSLCertificateFile應該是您的證書文件(例如your_domain_name.crt) SSLCertificateKeyFile應該是您在創建CSR時生成的密鑰文件。

7.重啟伺服器

 systemctl restart httpd.service
 (重啟會可能會因為沒有輸入RSA密碼導致無法開啟網頁)

 systemctl status httpd.service


8.因為SSL 導致每次重啟httpd都要輸入密碼 ,使用自動輸入密碼功能
 (重啟會可能會因為沒有輸入RSA密碼導致無法開啟網頁)

vim /etc/httpd/conf.d/ssl.conf

把原來的

SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog

改成

SSLPassPhraseDialog exec:/usr/libexec/autosslkey.sh

然後下指令
vim /usr/libexec/autosslkey.sh

autosslkey.sh只要這様寫
#!/bin/bash
echo 'your pass phrase'

接著權限允許

chmod 777 autosslkey.sh


參考連結2

參考連結3