What the message looks like
dovecot: imap(user@example.com): Error: open(/var/mail/user) failed: Permission denied (euid=1000(user) egid=1000(user) missing +w perm: /var/mail, dir owned by 0:8 mode=0775)Common causes
- The mail files belong to another user than the one Dovecot uses, for example after copying as root.
mail_locationpoints to the wrong path, or the directory does not exist.mail_uid,mail_gidorfirst_valid_uiddo not match the real owner.- The system mailbox
/var/mailneeds the mail group, which Dovecot does not have. - SELinux or AppArmor blocks access to the mail directory.
Check
- Which location and user settings are active?
doveconf -n | grep -E 'mail_location|mail_uid|mail_gid|first_valid_uid' - Who owns the mail directory?
ls -ld /var/mail /var/vmail - What does Dovecot think for this account?
doveadm user user@example.com - The exact errors
Fix
- Set the right location, for example
mail_location = maildir:/var/vmail/%d/%normaildir:~/Maildir. - Fix the owner:
chown -R vmail:vmail /var/vmailandchmod -R u+rwX,g-rwx,o-rwx /var/vmail. - Make
mail_uidandmail_gidmatch that owner, andfirst_valid_uidlower than it. - For
/var/mail, setmail_privileged_group = mailso Dovecot can create lock files. - Reload:
doveadm reloadand test the login again.
Typical scenario
You copied mailboxes from an old server to /var/vmail with rsync. IMAP login works, but the mail client shows no folders, and the log says "open(…) failed: Permission denied (euid=5000(vmail))". On the old system the mail user had a different UID, and rsync carried the owner IDs over. With ls -ln /var/vmail compare the numeric UID of the files with mail_uid from the Dovecot configuration.
FAQ
Why does it work for new mail but not for old mail?
Old files were created by another user or tool. Fix the owner for the whole mail tree, not only for new folders.
Do Postfix and Dovecot have to use the same user?
For local delivery, the user who writes the files and the user who reads them must be able to access the same files. A virtual mail user such as vmail for both is the simplest setup.
Why does ls -l show the right name but it still fails?
Permissions are tied to the numeric UID, not the name. Two systems can use the same name with different numbers. ls -ln shows the numbers. When copying, rsync --numeric-ids only helps if both sides use the same IDs; otherwise set the owner again with chown afterwards.
How do I test access as the mail user?
sudo -u vmail ls -l /var/vmail/example.com/anna shows whether that user can read the files. doveadm user anna@example.com shows which UID, home and mail path Dovecot derives for the account, and doveconf -n the configuration actually in effect.
Can SELinux trigger the error although the owner is right?
Yes, on systems with SELinux enabled. The security policy then denies access despite matching Unix permissions. ausearch -m avc -ts recent gives hints, and ls -Z shows the file context. On Debian and Ubuntu SELinux is not active by default.