admin 发表于 2026-10-9 13:06:58

通过如上章节的配置,使用系统用户可以登录到postfix邮件服务器,并且进行邮件的发送和接收,为了管理的方便和系统安全,一般通过postfix虚拟用户来管理邮件用户的。<br><br>Postfix虚拟用户的原理:基于系统中创建的一个映射用户,该用户不能登录到系统,然后将其他虚拟用户全部映射到该系统用户所属目录。<br><br>对于操作系统来说所有的操作均是通过该系统用户进行的,但是对于postfix的邮件用户来说又是各自独立的。Postfix虚拟用户与Vsftpd虚拟用户相似,所有的虚拟用户或者系统用户可以通过Postfixadmin来进行管理。<br><br>配置Postfix SMTP认证基于MYSQL数据库,读取MYSQL虚拟用户配置:<br><br>修改Postfix真实用户的uid和gid,命令如下:<br><br>usermod-u 1000 postfix<br><br>groupmod -g 1000 postfix<br><br>chown-Rpostfix.postfix /var/spool/mail/<br><br>创建postfix主配置文件mail.cf内容为如下:<br><br>queue_directory = /var/spool/postfix<br><br>command_directory = /usr/sbin<br><br>daemon_directory = /usr/libexec/postfix<br><br>data_directory = /var/lib/postfix<br><br>mail_owner = postfix<br><br>myhostname = mail.jingfengjiaoyu.com<br><br>mydomain = jingfengjiaoyu.com<br><br>myorigin = $mydomain<br><br>inet_interfaces = all<br><br>inet_protocols = ipv4<br><br>#mydestination = localhost<br><br>#mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain<br><br>unknown_local_recipient_reject_code = 550<br><br>#mynetworks = 192.168.0.0/24,127.0.0.0/8<br><br>mynetworks = 0.0.0.0/0<br><br>relay_domains = $mydestination<br><br>alias_maps = hash:/etc/aliases<br><br>alias_database = hash:/etc/aliases<br><br>debug_peer_level = 2<br><br>debugger_command =<br><br>PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin<br><br>ddd $daemon_directory/$process_name $process_id &amp; sleep 5<br><br>sendmail_path = /usr/sbin/sendmail.postfix<br><br>newaliases_path = /usr/bin/newaliases.postfix<br><br>mailq_path = /usr/bin/mailq.postfix<br><br>setgid_group = postdrop<br><br>html_directory = no<br><br>manpage_directory = /usr/share/man<br><br>sample_directory = /usr/share/doc/postfix-2.6.6/samples<br><br>readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES<br><br>#Config Virtual Mailbox Settings 2026<br><br>virtual_minimum_uid = 100<br><br>virtual_mailbox_base = /var/spool/mail<br><br>virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf<br><br>virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf<br><br>virtual_alias_domains = $virtual_alias_maps<br><br>virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf<br><br>virtual_uid_maps = static:1000<br><br>virtual_gid_maps = static:1000<br><br>virtual_transport = virtual<br><br>maildrop_destination_recipient_limit = 1<br><br>maildrop_destination_concurrency_limit = 1<br><br>#ConfigQUOTA2026<br><br>message_size_limit = 52428800<br><br>mailbox_size_limit = 209715200<br><br>virtual_mailbox_limit = 209715200<br><br>virtual_create_maildirsize = yes<br><br>virtual_mailbox_extended = yes<br><br>virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf<br><br>virtual_mailbox_limit_override = yes<br><br>virtual_maildir_limit_message = Sorry, the user&#x27;s maildir has overdrawn his diskspace quota, please try again later.<br><br>virtual_overquota_bounce = yes<br><br>#Config SASL 2026<br><br>broken_sasl_auth_clients = yes<br><br>smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit<br><br>smtpd_sasl_auth_enable = yes<br><br>smtpd_sasl_type = dovecot<br><br>smtpd_sasl_path = /var/run/dovecot/auth-client<br><br>smtpd_sasl_local_domain = $myhostname<br><br>smtpd_sasl_security_options = noanonymous<br><br>smtpd_sasl_application_name = smtpd<br><br>smtpd_banner=$myhostname SMTP &quot;Version not Available&quot;<br><br>创建POSTFIX读取MYSQL配置信息:<br><br>cat&gt;/etc/postfix/mysql_virtual_alias_maps.cf&lt;&lt;EOF<br><br>user = postfix<br><br>password = postfix<br><br>hosts = localhost<br><br>dbname = postfix<br><br>table = alias<br><br>select_field = goto<br><br>where_field = address<br><br>EOF<br><br>cat&gt;/etc/postfix/mysql_virtual_domains_maps.cf&lt;&lt;EOF<br><br>user = postfix<br><br>password = postfix<br><br>hosts = localhost<br><br>dbname = postfix<br><br>table = domain<br><br>select_field = description<br><br>where_field = domain<br><br>EOF<br><br>cat&gt;/etc/postfix/mysql_virtual_mailbox_limit_maps.cf&lt;&lt;EOF<br><br>user = postfix<br><br>password = postfix<br><br>hosts = localhost<br><br>dbname = postfix<br><br>table = mailbox<br><br>select_field = quota<br><br>where_field = username<br><br>EOF<br><br>cat&gt;/etc/postfix/mysql_virtual_mailbox_maps.cf&lt;&lt;EOF<br><br>user = postfix<br><br>password = postfix<br><br>hosts = localhost<br><br>dbname = postfix<br><br>table = mailbox<br><br>select_field = maildir<br><br>where_field = username<br><br>EOF<br><br>mysql_virtual_mailbox_maps.cf:服务器邮箱文件的存储路径。<br><br>mysql_virtual_domains_maps.cf:邮件服务器上所有的虚拟域。<br><br>mysql_virtual_alias_maps.cf:邮件服务器上虚拟别名和实际邮件地址间的对应关系。<br><br>mysql_virtual_mailbox_limit_maps.cf:服务器上邮箱的一些限制参数。<br><br>如上配置文件可以供Postfix读取数据库表。<br><br>默认是基于hash:/etc/aliases查询表,哈希文件,文件的路径是/etc/aliases。Postfix在需要的时候读取这些配置信息,然后根据这些配置信息的指示,到另外的文件或者数据库中去读取实际的数据。<br><br>创建数据库并授权:<br><br>create database postfix charset=utf8;<br><br>grant all privileges on postfix.* to postfix@&#x27;localhost&#x27; identified by &quot;postfix&quot;;<br><br>flush privileges;<br><br>修改postfixadmin配置文件数据库连接信息:<br><br><img src="https://bbs.jfedu.net/jf_imgs/image835.png" alt="" style="max-width:100%;"><br><br>通过Postfixamin创建4个虚拟用户,如图所示:<br><br><img src="https://bbs.jfedu.net/jf_imgs/image836.png" alt="" style="max-width:100%;"><br><br>配置Dovecot服务,修改dovecot.conf配置文件代码如下:<br><br>#/etc/dovecot/dovecot.conf<br><br>#OpenEuler: Linux 2.6.32<br><br>#2026年7月1日09:53:30<br><br>auth_mechanisms = PLAIN LOGIN<br><br>#auth_mechanisms = PLAIN LOGIN CRAM-MD5 DIGEST-MD5<br><br>disable_plaintext_auth = no<br><br>first_valid_uid = 1000<br><br>listen = *<br><br>mail_location = maildir:/var/spool/mail/%d/%n<br><br>managesieve_notify_capability = mailto<br><br>managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date<br><br>passdb {<br><br>args = /etc/dovecot/mysql.conf<br><br>driver = sql<br><br>}<br><br>protocols = imap pop3<br><br>service auth {<br><br>unix_listener auth-client {<br><br>group = postfix<br><br>mode = 0660<br><br>user = postfix<br><br>}<br><br>}<br><br>ssl = no<br><br>userdb {<br><br>args = /etc/dovecot/mysql.conf<br><br>driver = sql<br><br>}<br><br>创建Dovecot连接MYSQL认证,配置文件<br><br>/etc/dovecot/mysql.conf代码如下:<br><br>driver = mysql<br><br>connect = host=/var/lib/mysql/mysql.sock dbname=postfix user=postfix password=postfix<br><br>default_pass_scheme = MD5<br><br>password_query = SELECT password FROM mailbox WHERE username = &#x27;%u&#x27;<br><br>user_query = SELECT maildir, 1000 AS uid, 1000 AS gid FROM mailbox WHERE username = &#x27;%u&#x27;<br><br>使用虚拟用户登录RoundCube,如图所示:<br><br><img src="https://bbs.jfedu.net/jf_imgs/image837.png" alt="" style="max-width:100%;"><br><br><img src="https://bbs.jfedu.net/jf_imgs/image838.png" alt="" style="max-width:100%;">
页: [1]
查看完整版本: Postfix虚拟用户配置