您的位置:首頁技術文章
文章詳情頁

CentOS郵件服務器搭建系列——用 SSL 對郵件加密的支持

瀏覽:102日期:2024-07-11 10:04:58

前言

通常,我們發送的郵件在傳輸過程中都采用明文傳輸。當發送重要信息的時候,仍然存在郵件被第三方獲取,泄露隱私及密碼等等的安全隱患。在 Web 服務器中,通過用 SSL 實現對 HTTPS 協議的支持,實現了對傳輸內容的加密,在郵件服務器中,我們也同樣能夠依靠 SSL 來實現對郵件的加密,從而提高通過用郵件傳遞信息的安全性。

證書與密鑰的確認

在這里,可以為郵件服務器建立新的證書,但為了管理上的便利性,我們直接引用 Web 服務器的證書,作為郵件服務器的證書。

首先確認 Web 服務器證書的存在。

[root@sample ~]# ls -l /etc/httpd/conf/ssl.crt/server.crt  ← 確認證書的存在性

-rw-r--r-- 1 root root 956 Oct 14 08:51 /etc/httpd/conf/ssl.crt/server.crt  ← 證書存在

[root@sample ~]# ls -l /etc/httpd/conf/ssl.key/server.key  ← 確認密鑰的存在性

-rw------- 1 root root 887 Oct 14 08:49 /etc/httpd/conf/ssl.key/server.key  ← 密鑰存在

如果以上確認,沒有發現相關的證書和密鑰的存在,請參見 “讓服務器支持安全 HTTP 協議( HTTPS )” 中的方法來建立相關的證書和密鑰。

SMTP服務器(Postfix)方面的相關設置

[1] 編輯 Postfix 的 mail.cf 配置文件。

[root@sample ~]# vi /etc/postfix/main.cf  ← 編輯 Postfix 配置文件,在文尾添加如下行:

smtpd_use_tls = yessmtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scachesmtpd_tls_cert_file = /etc/httpd/conf/ssl.crt/server.crtsmtpd_tls_key_file = /etc/httpd/conf/ssl.key/server.key

[2] 編輯 Postfix 的 master.cf 配置文件。

[root@sample ~]# vi /etc/postfix/master.cf  ← 編輯 master.cf

smtp inet n - n - - smtpd  ← 找到此行,在行首加“#”↓#smtp inet n - n - - smtpd  ← 改為此狀態,禁用SMTP協議

#smtps inet n - n - - smtpd  ← 找到此行,去掉行首的“#”↓smtps inet n - n - - smtpd  ← 改為此狀態,使用SMTPS協議

# -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes  ← 找到此行,去掉行首的“#”↓-o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes  ← 改為此狀態

[3] 編輯 Dovecot 的配置文件。

[root@sample ~]# vi /etc/dovecot.conf  ← 編輯 Dovecot 的配置文件

protocols = imap pop3  ← 找到此行,將“=”后面的部分改為如下狀態↓protocols = imaps pop3s  ← 改為此狀態,讓其只支持imaps和pop3s協議

#ssl_disable = no  ← 找到此行,去掉行首的“#”↓ssl_disable = no  ← 改為此狀態,讓其支持 SSL 及 TLS

#ssl_cert_file = /usr/share/ssl/certs/dovecot.pem  ← 找到此行,去掉行首的“#”,并指定證書所在位置↓ssl_cert_file =/etc/httpd/conf/ssl.crt/server.crt  ← 改為此狀態,指定其證書為 Apache 的證書↓#ssl_key_file = /usr/share/ssl/private/dovecot.pem  ← 找到此行,去掉行首的“#”,并指定密鑰所在位置

ssl_key_file = /etc/httpd/conf/ssl.key/server.key   ← 改為此狀態,指定其密鑰為 Apache 的密鑰

[4] 編輯防火墻規則,打開相應端口。

[root@sample ~]# vi /etc/sysconfig/iptables  ← 編輯防火墻規則

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT  ← 找到此行,接著添加如下行:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT  ← 允許SMTPS的465號端口-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 995 -j ACCEPT  ← 允許POP3S的995號端口-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 993 -j ACCEPT  ← 允許IMAPS的993號端口

重新起動相關服務,使設置生效

最后,重新啟動所有相關的服務,使剛剛的設置生效。

[root@sample ~]# /etc/rc.d/init.d/postfix restart  ← 重新啟動 Postfix

Shutting down postfix: [ OK ]Starting postfix: [ OK ]

[root@sample ~]# /etc/rc.d/init.d/dovecot restart  ← 重新啟動 Dovecot

Stopping Dovecot Imap:  [ OK ]Starting Dovecot Imap: [ OK ]

[root@sample ~]# /etc/rc.d/init.d/iptables restart  ← 重新啟動 iptables

Flushing firewall rules:  [ OK ]Setting chains to policy ACCEPT: filter [ OK ]Unloading iptables modules: [ OK ]Applying iptables firewall rules:  [ OK ]

郵件客戶端的設置

這里,郵件客戶端的設置以 Thunderbird 為例。

* SMTP 方面:

在 SMTP 服務器設置中,選擇 SSL 方式。使用 Thunderbird 的情況下,選擇 SSL 后,端口號會自動變成 465。其它郵件客戶端軟件請根據實際情況正確設置。

標簽: CentOS
相關文章:
国产综合久久一区二区三区