How to Forward Root’s Mail to a Another User in FreeBSD

(20190119 — The steps in this post were amended to address changes in recent versions of software — iceflatline)

After setting up a FreeBSD system I can sometimes go long stretches without becoming the superuser again. When I finally do issue the su command I’m usually presented with the line “You have mail.” I sigh and enter the command mail, where I’m presented with a multitude of system-generated mail updating me on everything from the status of cron jobs that have run (or not) to security and daily run reports. It’s at this point that I think to myself “I really need to forward that mail to my inbox so I read them more often.” This post will describe how to setup FreeBSD so that the root user’s mail is forwarded to another user account.

The versions for the software used in this post are as follows:

  • FreeBSD 12.0-RELEASE

To forward the root user’s mail to another users’ inbox open the file /etc/aliases as root and look for the following line:

Uncomment this line and replace “me@my.domain” with the user name you’d like the mail forwarded to. For example, to forward root’s mail to the user iceflatline on the same host, the line would look like this:

Now we need to make the sendmail (sendmail is the default Mail Transfer Agent in FreeBSD) aware of the changes we’ve made to /etc/aliases before they’ll take effect: We’ll do that by using the newaliases command as root:

Now any mail the system (or anyone else) sends to root will also be forwarded to the user iceflatline’s mail inbox. To test whether mail is indeed being forwarded use the mail command to send root a message. Start by specifying a subject, then hit enter and type the message. When complete, hit enter enter again to place the cursor at the beginning of a blank line, then enter CTRL+D to send the message:

Now enter the mail command at the user prompt and you should see the message you just sent to the root user:

Conclusion

Well, that’s it. A couple of tweaks on FreeBSD and you’ll have no excuse for missing those system reports.

Leave a Reply

Your email address will not be published. Required fields are marked *

iceflatline