个人工具
登录
查看“Serverguide”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“Serverguide”的源代码
来自Ubuntu中文
←
Serverguide
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
===== 4.14.1. Postfix ===== Postfix 是 Ubuntu 中缺省的邮件传输代理 (MTA)。它试图变得快捷、易于管理和安全。它与 MTA sendmail 兼容。这部分内容说明如何安装和配置 postfix。还说明如何将它设置成使用安全连接的 SMTP 服务器 (为了安全发送邮件)。 ====== 4.14.1.1. 安装 ====== 要安装带有 SMTP-AUTH 和 传输层安全 (TLS) 的 postfix,运行下列命令: <pre><nowiki> sudo apt-get install postfix</nowiki></pre> 当安装进程提问时简单地按回车,下面将详细说明相关配置。 ====== 4.14.1.2. 基本配置 ====== 要配置 postfix,运行下列命令: <pre><nowiki> sudo dpkg-reconfigure postfix</nowiki></pre> 用户界面将显示。在每一屏中,选择下列值: <pre><nowiki> **** Ok **** Internet 站点 **** NONE **** mail.example.com **** mail.example.com, localhost.localdomain, localhost **** No **** 127.0.0.0/8 **** Yes **** 0 **** + **** 全部 </nowiki></pre> 把 mail.example.com 作为您的邮件服务器的主机名。 ====== 4.14.1.3. SMTP 认证 ====== 下一步是为 postfix 的 SMTP AUTH 配置使用 SASL。与其直接编辑配置,不如使用 postconf 命令配置所有 postfix 参数。配置参数被保存在 /etc/postfix/main.cf 文件中。如果您希望更新配置一项参数,您可以运行命令或手工在文件中修改。 *** 配置 Postfix 使用 SASL (saslauthd) 的 SMTP AUTH : <pre><nowiki> postconf -e 'smtpd_sasl_local_domain =' postconf -e 'smtpd_sasl_auth_enable = yes' postconf -e 'smtpd_sasl_security_options = noanonymous' postconf -e 'broken_sasl_auth_clients = yes' postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination' postconf -e 'inet_interfaces = all' echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf</nowiki></pre> *** 接下来为 TLS 配置数字证书。当被询问问题时,按照提示并适当回答。 <pre><nowiki> openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024 chmod 600 smtpd.key openssl req -new -key smtpd.key -out smtpd.csr openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt openssl rsa -in smtpd.key -out smtpd.key.unencrypted mv -f smtpd.key.unencrypted smtpd.key openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 mv smtpd.key /etc/ssl/private/ mv smtpd.crt /etc/ssl/certs/ mv cakey.pem /etc/ssl/private/ mv cacert.pem /etc/ssl/certs/</nowiki></pre> 您可以从证书颁发机构得到数字证书。或者您可以创建您自己的证书。详情参考 第4.10.3.4节 ― 创建一个自己签署的证书。 *** 配置 Postfix 对接收或发送邮件进行 TLS 加密: <pre><nowiki> postconf -e 'smtpd_tls_auth_only = no' postconf -e 'smtp_use_tls = yes' postconf -e 'smtpd_use_tls = yes' postconf -e 'smtp_tls_note_starttls_offer = yes' postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key' postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt' postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem' postconf -e 'smtpd_tls_loglevel = 1' postconf -e 'smtpd_tls_received_header = yes' postconf -e 'smtpd_tls_session_cache_timeout = 3600s' postconf -e 'tls_random_source = dev:/dev/urandom' postconf -e 'myhostname = mail.example.com'</nowiki></pre> 在您运行所有命令之后,postfix 的 SMTP AUTH 将被配置。将为 TLS 创建自己签署的证书并与 postfix 一起配置。 现在文件 /etc/postfix/main.cf 看上去就象 这样。 postfix 初始配置完成。运行下列命令以开始 postfix 守护程序: <pre><nowiki> sudo /etc/init.d/postfix start</nowiki></pre> 现在 postfix 已经被安装、配置及成功运行。Postfix 支持在 RFC2554 中定义的 SMTP AUTH。它基于 SASL。无论如何在您使用 SMTP 之前必须设置 SASL 认证。 ====== 4.14.1.4. 配置 SASL ====== libsasl2、sasl2-bin 和 libsasl2-modules 对于使用 SASL 的 SMTP AUTH 是必需的。如果您没有安装它们的话,您可以安装这些应用程序。 <pre><nowiki> apt-get install libsasl2 sasl2-bin</nowiki></pre> 要让其正常工作的话做一些改动是必须的。因为 Postfix 是被 chroot 在 /var/spool/postfix 中运行,SASL 需要被配置在假根目录中运行 (从 /var/run/saslauthd 到 /var/spool/postfix/var/run/saslauthd): <pre><nowiki> mkdir -p /var/spool/postfix/var/run/saslauthd rm -rf /var/run/saslauthd</nowiki></pre> 要激活 saslauthd,编辑文件 /etc/default/saslauthd,并修改或添加 START 变量。为了将 saslauthd 配置成在假根目录中运行,添加 PWDIR、PIDFILE 和 PARAMS 变量。最终,随您所好配置 MECHANISMS 变量。该文件看起来象这样: <pre><nowiki> # This needs to be uncommented before saslauthd will be run # automatically START=yes PWDIR="/var/spool/postfix/var/run/saslauthd" PARAMS="-m ${PWDIR}" PIDFILE="${PWDIR}/saslauthd.pid" # You must specify the authentication mechanisms you wish to use. # This defaults to "pam" for PAM support, but may also include # "shadow" or "sasldb", like this: # MECHANISMS="pam shadow" MECHANISMS="pam" </nowiki></pre> 如果您喜欢,您可以使用 shadow 代替 pam。这将使用 MD5 哈希密码传输并更为安全。需要认证的用户名和密码将是您正在服务器上使用系统的那些用户。 接下来更新 /var/spool/portfix/var/run/saslauthd 的 dpkg "state"。saslauthd 初始化脚本将使用该设置来创建有着适当权限和所有权的目录: <pre><nowiki> dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd</nowiki></pre> ====== 4.14.1.5. 测试 ====== SMTP AUTH 配置完成。现在是启动并测试设置的时候了。您可以运行下列命令来启动 SASL 守护程序: <pre><nowiki> sudo /etc/init.d/saslauthd start</nowiki></pre> 要查看 SMTP-AUTH 和 TLS 是否正常工作,运行下列命令: <pre><nowiki> telnet mail.example.com 25</nowiki></pre> 在您建立到 postfix 邮件服务器连接之后,输入: <pre><nowiki> ehlo mail.example.com</nowiki></pre> 如果您看到包括下列行时,那么一切工作正常。输入 quit 退出。 <pre><nowiki> 250-STARTTLS 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250 8BITMIME</nowiki></pre>
返回至
Serverguide
。