Prepare Dovecot to use virtual users

By default, Dovecot performs many actions on the file system as the user who uses the service. However, configuring the Dovecot back end to use one local user to perform these actions has several benefits.

Before you begin

  • Dovecot is installed.

About this task

Using one local user for Dovecot file system actions provides the following benefits:

  • Dovecot performs file system actions as a specific local user instead of using the user’s ID (UID).
  • Users do not need to be available locally on the server.
  • You can store all mailboxes and user-specific files in one root directory.
  • Users do not require a UID and group ID (GID), which reduces administration efforts.
  • Users who have access to the file system on the server cannot compromise their mailboxes or indexes because they cannot access these files.
  • Configuring replication is easier.

Procedure

  1. Create the vmail user:
    # useradd --home-dir /var/mail/ --shell /usr/sbin/nologin vmail

    Dovecot will later use this user to manage the mailboxes. For security reasons, do not use the dovecot or dovenull system users for this purpose.

  2. If you use a different path than /var/mail/, set the mail_spool_t SELinux context on it, for example:
    # semanage fcontext -a -t mail_spool_t "<path>(/.)?"*
    # restorecon -Rv <path>
  3. Grant write permissions on /var/mail/ only to the vmail user:
    # chown vmail:vmail /var/mail/
    # chmod 700 /var/mail/
  4. Uncomment the mail_location parameter in the /etc/dovecot/conf.d/10-mail.conf file, and set it to the mailbox format and location:
    mail_location = sdbox:/var/mail/%n/

    With this setting:

    • Dovecot uses the high-performance dbox mailbox format in single mode. In this mode, the service stores each mail in a separate file, similar to the maildir format.
    • Dovecot resolves the %n variable in the path to the username. This is required to ensure that each user has a separate directory for its mailbox.

What to do next