3
$ uname -a
Linux xxxx 4.9.0-4-amd64 #1 SMP Debian 4.9.51-1 (2017-09-28) x86_64 GNU/Linux

$ cat  /etc/aliases
# See man 5 aliases for format
postmaster:    root
root:          root@xxxx.xxxx

email received by nobody.

$ sudo mail -f  /var/spool/mail/nobody
"/var/spool/mail/nobody": 23 messages 1 new 19 unread
     1 Anacron            Tue Jan  9 00:07  20/823   Anacron job 

'cron.daily' on xxxx
From: Anacron <root@xxxx.xxxx>
To: root@xxxx.xxxx
Subject: Anacron job 'cron.daily' on xxxx
Content-Type: text/plain; charset=UTF-8

Why is an email sent to root redirected to nobody?

$ sudo mail -f  /var/spool/mail/root
/var/spool/mail/root: 0 messages

No email in root's mail box.
Send an email to root to test.

$  echo "This is the body of the email" | mail -s "This is the subject line" root

All of them can receive the email.

 $ sudo mail -f /var/spool/mail/root
 $ sudo mail -f /var/mail/root
 $ sudo mail -f /root/Maildir

Only nobody can receive the email .

$ sudo mail -f /var/spool/mail/nobody

Log info in /var/log/mail.log

$ sudo cat /var/log/mail.log
Apr 27 17:48:43 xxxx postfix/pickup[7114]: 1FE0D2801E3: uid=1000 from=<debian9@xxxx.xxxx>
Apr 27 17:48:43 xxxx postfix/cleanup[7492]: 1FE0D2801E3: message-id=<20180427094843.1FE0D2801E3@xxxx.xxxx>
Apr 27 17:48:43 xxxx postfix/qmgr[1394]: 1FE0D2801E3: from=<debian9@xxxx.xxxx>, size=360, nrcpt=1 (queue active)
Apr 27 17:48:43 xxxx postfix/local[7494]: 1FE0D2801E3: to=<root@xxxx.xxxx>, relay=local, delay=0.21, delays=0.17/0/0/0.04, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
Apr 27 17:48:43 xxxx postfix/qmgr[1394]: 1FE0D2801E3: removed

Why does postfix redirect email from root to nobody?

John Kugelman
  • 103
  • 12
scrapy
  • 337
  • 4
  • 16

3 Answers3

9

As some material states:
procmail

Root's mail is delivered to nobody If you use procmail (or some other command) for local mail delivery, Postfix will not deliver mail as root. Instead, Postfix runs procmail (or whatever) as nobody. Perhaps some day Wietse will trust Postfix enough to run external commands as root.

Postfix not only runs procmail (or whatever) as nobody, but also deliver email to nobody as root.

Some old material in the web: Strange delivery in postfix/procmail configuration

Postfix's own delivery agent can deliver to root's mailbox, but postfix will NEVER fork an external program (e.g. procmail) as root. it either changes UID to the owner of the mail being delivered or if that user is root, then it changes UID to nobody.

So procmail gets run as nobody when delivering root's mail.

scrapy
  • 337
  • 4
  • 16
2

Check for the existence of a file named $HOME/.forward. If this file exists, and contains an email address or local username, then incoming mail for the user who owns the file will be forwarded to the address given.

For instance, it might look like this:

debian9@hwy:~$ sudo cat /root/.forward
nobody
debian9@hwy:~$
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
1

As pointed out by the user @scrapy, the redirection/forward is being accomplished by procmail. Look at your /etc/postfix/main.cf to check if this line is present: mailbox_command = procmail -a "$EXTENSION" (just to make sure that procmail is setup).

For the root user to receive emails, you can simply link the root mbox to nobody mbox, like this (if you are using mbox):

ln -s /var/mail/{nobody,root}
rodvlopes
  • 111
  • 3