[
    {
        "role": "user",
        "content": "I%27m%20running%20debian%2013%20with%20exim4.%20when%20I%20send%20a%20mail%20to%20root%2C%20it%20seems%20to%20end%20up%20in%20%2Fvar%2Fmail%2Fmail.%20why%20is%20this%3F%20shouldn%27t%20it%20go%20to%20%2Fvar%2Fmail%2Froot%20%3F"
    },
    {
        "role": "assistant",
        "content": "Here\u2019s what I found: in Debian with Exim4, it is *possible* and even common for mail addressed to `root` to end up in the mailbox of another user\u2014often the generic `mail` user\u2014unless you've explicitly set up an alias or configuration to redirect it to `/var/mail/root`. I\u2019ll explain why this happens by default, and what you can do if you want `root` mail to go to `root`.\n\n---\n\n## What\u2019s going on by default\n\n1. **`/etc/aliases` redirecting root**  \n   Debian\u2019s Exim4 package includes an \u201caliases\u201d file where (often commented-out) lines suggest you *should* set up root's mail to go to a user account. The file encourages you to do so for security and administrative reasons. ([sources.debian.org](https://sources.debian.org/src/exim4/4.89-2%2Bdeb9u1~bpo8%2B1/src/aliases.default?utm_source=openai))\n\n2. **Default creation of a \u201cmail\u201d user alias**  \n   If during the Exim4 configuration (especially with `dpkg-reconfigure exim4-config`) you don\u2019t set up a specific alias for `root`, Debian may redirect `root` to a non-root user\u2014often `mail`\u2014by default. This is so that system messages still land in a mailbox that's checked regularly without needing to login as `root`. A manual for \u201cDebian Edu\u201d stated \u201croot email is now delivered to /var/mail/mail, not /var/mail/root\u201d in the default setup. ([wiki.debian.org](https://wiki.debian.org/DebianEdu/HowTo/PublicMailServer%28SMTP%29?utm_source=openai))\n\n3. **Exim\u2019s routers and default behavior**  \n   Exim checks `/etc/aliases` for local name redirection, but also applies rewriting and router rules (based on things like `/etc/mailname`, `dc_other_hostnames`, etc.) that may transform root addresses. If an alias isn\u2019t defined, root gets delivered like any other local user *unless* there\u2019s a default alias. ([linuxquestions.org](https://www.linuxquestions.org/questions/linux-server-73/exim4-cannot-deliver-the-messages-to-the-local-mail-box-4175591263/?utm_source=openai))\n\n---\n\n## Why `/var/mail/mail` instead of `/var/mail/root`\n\nBecause `root` is being aliased to the `mail` user (or whichever user is used in that alias), Exim delivers `root`\u2019s mail to that user\u2019s spool\u2014`/var/mail/mail`. The name comes from the alias, i.e. `root: mail`. This was likely part of your Exim4 setup, either manually or by choosing default during install/configure, which didn\u2019t specify otherwise. The `mail` user is often used in Debian setups for system mail.\n\n---\n\n## What you should do if you want mail in `/var/mail/root`\n\nIf you want mail sent to root to go *specifically* to `/var/mail/root`, here\u2019s how you can assure that happens:\n\n1. Edit `/etc/aliases`. Add or uncomment a line like:\n\n   ```\n   root: root\n   ```\n\n   That ensures \u201croot\u201d mail isn\u2019t redirected to \u201cmail\u201d or some other user.\n\n2. Run:\n\n   ```\n   sudo newaliases\n   ```\n\n   to make sure Exim reads and applies the alias changes.\n\n3. Check `/etc/exim4/update-exim4.conf.conf` and the related configuration to ensure there\u2019s no rewriting rule for `root` pointing elsewhere (or via `/etc/email-addresses`). Sometimes `/etc/email-addresses` is used to rewrite addresses for outgoing mail too. ([manpages.debian.org](https://manpages.debian.org/testing/exim4-config/etc-aliases.5.en.html?utm_source=openai))\n\n4. Restart Exim to apply the changes:\n\n   ```\n   sudo systemctl restart exim4\n   ```\n\n5. Test delivery:\n\n   ```\n   echo \"test message\" | mail -s \"test to root\" root\n   ```\n\n   Then check `/var/mail/root` to see if the mail arrived there.\n\n---\n\n## Summary\n\n- It\u2019s *not* a bug: Debian/Exim4\u2019s default behavior *can* be to deliver root\u2019s mail to another user\u2019s mailbox (often `mail`) via aliases.\n- If you want root\u2019s mail in its own mailbox (`/var/mail/root`), set the alias explicitly in `/etc/aliases` and run `newaliases`, then restart Exim.\n- Always check both `/etc/aliases` *and* any rewriting / address\u2010rewrite configurations (including `/etc/email-addresses`) to see where root is mapped.\n\nIf you tell me exactly what you have in your `/etc/aliases` and your `dc_other_hostnames` or `mailname` (from `/etc/mailname`), I can help you adjust them so root\u2019s mail goes where you prefer."
    }
]