(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:
1 |
# root: me@my.domain |
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:
1 |
root: iceflatline |
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:
1 |
newaliases |
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:
1 2 3 4 |
$ mail root Subject: Test of forwarding this is a test. EOT |
Now enter the mail command at the user prompt and you should see the message you just sent to the root user:
1 2 3 4 5 |
$ mail Mail version 8.1 6/6/93. Type ? for help. "/var/mail/iceflatline": 1 message 1 new >N 1 iceflatline@aragorn. Sat Sep 29 15:08 18/702 "Test of forwarding" & |
Conclusion
Well, that’s it. A couple of tweaks on FreeBSD and you’ll have no excuse for missing those system reports.