The configuration of postfix virtual user under Linux

Source: Internet
Author: User
Tags base64 chmod dovecot mysql database linux

1. Establish a virtual user database

[Root@mail ~] #service mysqld Restart//restart MySQL database

[Root@mail ~] #tar zxf extman-0.2.5.tar.gz

[Root@mail ~] #cd Extman-0.2.5/docs

[Root@mail docs] #mysql-u root-p123456 < extmail.sql//import extmail.sql script, root login database password 123456

[Root@mail docs] #mysql-u root-p123456 < init.sql//import Init.sql Script

The main database operations that the Extmail.sql script completes are as follows:

Create a database named Extmail and some tables in the library;

Establish the database user extmail@localhost, the initial password is extmail, the table in the database extmail has select, UPDATE permission;

Establish the database user webman@localhost, the initial password is Extman, the table in the database extmail has SELECT, INSERT, delete, update permissions.

The main database operations that the Init.sql script completes are as follows:

Initialize database extmail;

Establish a virtual mail domain named extmail.org;

Establish the database user root@extmail.org, the initial password is: extmail*123*, as the mail domain management account;

Set up the database user postmaster@extmail.org, the initial password is: Extmail, as the basic mail user.

2. Modify the configuration of the Postfix

[Root@mail docs] #vi/etc/postfix/main.cf

The configurations that support virtual users are:

Virtual_mailbox_base: Specifies the path start of the virtual mailbox store directory

Virtual_alias_maps: Specifies the alias file location for the virtual mail user

Virtual_mailbox_maps: Map Location of virtual mailbox address and storage location

Virtual_mailbox_domains: Domain Name

Virtual_uid_maps: Set the UID number of the local user mapping for the virtual mail user

Virtual_gid_maps: Set the GID number of the local group for the virtual Mail user map

3. Set SMTP letter authentication for virtual users:

1>. Compile Installation Courier-authlib Package:

[Root@mail ~] #tar jxf courier-authlib-0.60.2.tar.bz2

[Root@mail ~] #cd courier-authlib-0.60.2

[Root@mail courier-authlib-0.60.2]#./configure--prefix=/usr/local/courier-authlib--without-stdheaderdir-- With-authmysql--with-redhat--with-mysql-libs=/usr/local/mysql/lib/mysql--with-mysql-includes=/usr/local/mysql/ Include/mysql

[Root@mail courier-authlib-0.60.2] #make && make install

[Root@mail courier-authlib-0.60.2] #make install-configure

2> Modify the Courier-authlib related configuration and start the service:

Add the Courier-authlib library file path to the system's search path:

[Root@mail courier-authlib-0.60.2] #vi/etc/ld.so.conf

/usr/local/courier-authlib/lib/courier-authlib

[Root@mail courier-authlib-0.60.2] #ldconfig

Modify the AUTHDAEMONRC master configuration file, leaving only the Authmysql authentication method and removing other methods:

[Root@mail courier-authlib-0.60.2] #cd/usr/local/courier-authlib/etc/authlib

[Root@mail Authlib] #vi AUTHDAEMONRC

authmodulelist= "Authmysql"//configuration items that need to be modified

authmodulelistorig= "Authmysql"//configuration items that need to be modified

[Root@mail Authlib] #chmod-R 755/usr/local/courier-authlib/var/spool/authdaemon

Modify the AUTHMYSQLRC file to describe how to query the MySQL database for information:

[Root@mail Authlib] #vi AUTHMYSQLRC

mysql_server localhost \\MSYQL database server location

Mysql_username extmail \ Database Administrator account

Mysql_password extmail \ Database Administrator account password

Mysql_socket/tmp/mysql.sock \\mysql.sock File Location

Mysql_database extmail \ Virtual User Database

Mysql_user_table mailbox \ Heavy Mailbox table to obtain account information

Mysql_crypt_pwfield password \ Get account password from Pssword field

Mysql_uid_field uidnumber \ \ Obtains a mapped local user UID from the Uidnumber field

Mysql_gid_field gidnumber \ \ Get mapped local group GID from the Gidnumber field

Mysql_login_field username \ Get account name (with @ suffix) from username field

Mysql_home_field concat ('/mailbox/', homedir) \ \ Merge The full path of the user's host directory

This article URL address: http://www.bianceng.cn/OS/Linux/201410/45498.htm

Mysql_name_field name \ \ Get account names from the Name field (without the @ suffix)

Mysql_maildir_field concat ('/mailbox/', MAILDIR) \ \ Merge The user's full message store path

Copy the Courier-authlib script and start the Courier-authlib service:

[Root@mail Authlib] #cp courier-authlib.sysvinit/etc/init.d/courier-authlib// Courier-authlib.sysvinit files are located in the courier-authlib-0.60.2 directory after the source package is uncompressed

[Root@mail Authlib] #chmod 755/etc/rc.d/init.d/courier-authlib

[Root@mail Authlib] #service courier-authlib start

[Root@mail Authlib] #chkconfig--level courier-authlib on

3> modify Cyrus SASL settings: (Modify the Smtpd.conf file, which was established when building a system based user's mail system, and now change the authentication mode to Authdaemond, i.e. courier-authlib)

[Root@mail Authlib] #vi/usr/lib/sasl2/smtpd.conf

Pwcheck_method:authdaemond

Authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

4. Modify the configuration of the Dovecot:

The configuration of the 1>.dovecot file needs to be modified as follows:

[Root@mail ~]# vi/etc/dovecot.conf

Find mail_location change it to

Mail_location = Maildir:/mailbox/%d/%n/maildir

Find mechanisms = Plain Add the following below

Passdb SQL {

args =/etc/dovecot-mysql.conf

}

UserDB SQL {

args =/etc/dovecot-mysql.conf

}

2> Establish a database query configuration file:

[Root@mail ~]# vi/etc/dovecot-mysql.conf

Driver = MySQL

Connect = host=localhost dbname=extmail user=extmail password=extmail

Default_pass_scheme = encryption algorithm for cipher string stored in CRYPT \\MSYQL database

Password_query = SELECT username as user,password as password from mailbox WHERE username = '%u ' \ SQL statements for querying user passwords

User_query = SELECT Maildir, uidnumber as UID, gidnumber as GID from mailbox WHERE username = '%u ' \ \ SQL statements for querying users

3> Set up a virtual user postmaster@extmail.org mailbox directory, adjust permissions, and start the Dovecot service:

[Root@mail ~] #mkdir-P/mailbox/extmial.org/postmaster/maildir

[Root@mail ~] #chown-R Postfix:postfix/mailbox

[Root@mail Maildir] #killall-9 dovecot//If Dovecot service is started, perform this step first

[Root@mail Maildir] #dovecot

5. Test virtual User Implementation results:

1> Testing the Authlib service, you will see the authentication succeeded message if the previous configuration has not been wrong:

[Root@mail ~]#/usr/local/courier-authlib/sbin/authtest-s Login postmaster@extmail.org extmail

2>. Test the SMTP letter authentication for the virtual user, the "235 Authentication successful" message indicates success

[Root@mail ~]# perl-e ' use mime::base64; Print Encode_base64 ("Postmaster\ @extmail. org") '

[Root@mail ~]# perl-e ' use mime::base64; Print encode_base64 ("Extmail")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.