Complete Virtual Mail Server/Linux vmail user
The vmail user
Because valid UNIX user and group id's are needed to store the mailboxes, those should be created as well.
- Most services get a system ID under 1000.
- In Gentoo the user ID's start at 1000.
- An ID of 5000 is chosen for the vmail user.
If there are hundreds of shell users on the system a different ID can be used as well. For the vmail group the same is done. This will not be a shell account for anybody to log in with.
groupadd -g 5000 vmail
useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail
Nitpicking, specifying uid and gid isn't really required, but it's always tidy to think about it. After the users and groups have been added, it may wise to edit the /etc/passwd and /etc/group files and move the new user and group to an appropriate place. This because by default useradd and groupadd will increase the last found entry and thus a new user would be 5001. This obviously is only important if these files needed to be kept organized and clean.
Next to think about is the mail storage. This can be a partition, an NFS share or any ordinary sub-directory. Here /var/vmail is chosen as noted above and created as a 32GiB raid10 partition. Wherever it is chosen to be stored, ownership should be changed appropriately.
chown vmail:vmail /var/vmail/
Also permissions should be set up properly:
chmod 2770 /var/vmail/
Check the permissions to make sure that there will not be any permission error later:
ls -ld /var/vmail
Vmail user and Postfix
Postfix needs to know where and under what ownership to store mail.
If required, this also can be looked up on a per user basis from the database. For example, when the maildirs are not located in a central directory, but in each users home directory. In this document, the vmail user is the only user to be allowed access, and thus this is not touched on.
# Link the mailbox uid and gid to postfix.
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
# Set the base address for all virtual mailboxes
virtual_mailbox_base = /var/vmail