導讀 | 這么長時間之后,我的讀者們,這里是我給你們承諾的在 Apache 中使用 OpenSSL 的方法,下周你會看到在 Dovecot 中使用 SSL。 在這個分為兩部分的系列中,我們將學習如何創建自己的 OpenSSL 證書,以及如何配置 Apache 和 Dovecot 來使用它們。 |
Debian/Ubuntu/Mint 會在 /etc/ssl 中存儲私鑰和證書的符號鏈接。系統自帶的證書保存在/usr/share/ca-certificates 中。你安裝或創建的證書在 /usr/local/share/ca-certificates/ 中。
這個例子是對 Debian 而言。創建私鑰和公用證書,將證書轉換為正確的格式,并將其符號鏈接到正確的目錄:
$ sudo openssl req -x509 -days 365 -nodes -newkey rsa:2048 /-keyout /etc/ssl/PRivate/test-com.key -out //usr/local/share/ca-certificates/test-com.crtGenerating a 2048 bit RSA private key.......+++......................................+++writing new private key to '/etc/ssl/private/test-com.key'-----You are about to be asked to enter information that willbe incorporated into your certificate request.What you are about to enter is what is called a DistinguishedName or a DN. There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:USState or Province Name (full name) [Some-State]:WALocality Name (eg, city) []:SeattleOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Alrac Writing SweatshopOrganizational Unit Name (eg, section) []:home dungeonCommon Name (e.g. server FQDN or YOUR name) []:www.test.comEmail Address []:[email protected]$ sudo update-ca-certificatesUpdating certificates in /etc/ssl/certs...1 added, 0 removed; done.Running hooks in /etc/ca-certificates/update.d...Adding debian:test-com.pemdone.done.CentOS/Fedora 使用不同的文件結構,并不使用 update-ca-certificates,使用這個命令:
$ sudo openssl req -x509 -days 365 -nodes -newkey rsa:2048 /-keyout /etc/httpd/ssl/test-com.key -out //etc/httpd/ssl/test-com.crt最重要的條目是 Common Name,它必須與你的完全限定域名(FQDN)完全匹配。此外其它信息都是任意的。-nodes 用于創建一個無密碼的證書,這是 Apache 所必需的。-days 用于定義過期日期。更新證書是一個麻煩的事情,但這樣應該能夠額外提供一些安全保障。
>配置 Apache現在配置 Apache 以使用你的新證書。如果你遵循給初學者看的在 Ubuntu linux 上使用 Apache:第 2 部分,你所要做的就是修改虛擬主機配置中的 SSLCertificateFile 和 SSLCertificateKeyFile,以指向你的新私鑰和公共證書。來自該教程中的 test.com示例現在看起來像這樣:
SSLCertificateFile /etc/ssl/certs/test-com.pemSSLCertificateKeyFile /etc/ssl/private/test-com.keyCentOS 用戶,請參閱在 CentOS wiki 中的在 CentOS 上設置 SSL 加密的 Web 服務器一文。過程是類似的,wiki 會告訴如何處理 SELinux。
測試 Apache SSL一個簡單的方法是用你的網絡瀏覽器訪問 https://yoursite.com,看看它是否可以正常工作。在第一次這樣做時,你會在你過度保護的 web 瀏覽器中看到可怕的警告說網站是不安全的,因為它使用的是自簽名證書。請忽略你這個敏感的瀏覽器,并單擊屏幕創建永久性例外。 如果你遵循在給初學者看的在 Ubuntu Linux 上使用 Apache:第 2 部分上的示例虛擬主機配置,那么即使你的網站訪問者嘗試使用純 HTTP,你的網站的所有流量都將強制通過 HTTPS。
一個很好測試方法是使用 OpenSSL。是的,有一個漂亮的命令來測試這些東西。試下這個:
$ openssl s_client -connect www.test.com:443CONNECTED(00000003)depth=0 C = US, ST = WA, L = Seattle, O = Alrac Writing Sweatshop,OU = home dungeon, CN = www.test.com, emailAddress = [email protected] return:1---Certificate chain0 s:/C=US/ST=WA/L=Seattle/O=Alrac Writing Sweatshop/OU=homedungeon/CN=www.test.com/[email protected]:/C=US/ST=WA/L=Seattle/O=Alrac Writing Sweatshop/OU=homedungeon/CN=www.test.com/[email protected] certificate-----BEGIN CERTIFICATE-----[...]這里輸出了大量的信息。這里有很多關于 openssl s_client 的有趣信息; 現在足夠我們知道我們的 web 服務器是否使用了正確的 SSL 證書。
創建一個證書簽名請求如果你決定使用第三方證書頒發機構(CA),那么就必須創建證書簽名請求(CSR)。你將它發送給你的新 CA,他們將簽署并將其發送給您。他們可能對創建你的 CSR 有自己的要求; 這是如何創建一個新的私鑰和 CSR 的典型示例:
$ openssl req -newkey rsa:2048 -nodes /-keyout yourdomain.key -out yourdomain.csr你也可以從一個已經存在的 key 中創建一個 CSR:
$ openssl req -key yourdomain.key /-new -out domain.csr今天就是這樣了。下周我們將學習如何正確地在 Dovecot 中設置 OpenSSL。
本文
免費提供最新Linux技術教程書籍,為開源技術愛好者努力做得更多更好,開源站點:http://www.linuxprobe.com/
新聞熱點
疑難解答