2006-11-10

Which machine's "root" is mailing me?

Tim Bagot had a cunning solution to a problem we had at work recently. A machine was unhappy, and we were getting a lot of mail from "root".

All mail from root, regardless of source machine, ends up mailed to the same recipients. Usually mail will have enough information in the subject line or content to let us know what machine's unhappy. Sometimes it doesn't, though, and then you're left telling your mailer to show you more header information, and that's a pointless hassle. (Many mobile devices' mail readers don't even have an option to show you the headers.)

You might wonder "why don't you have the MTA properly qualify any unqualified names it sees?", but it's pretty common that you are doing that, but to get email addresses that are usable outside your organization. So "your-mum" becomes "your-mum@jessies.org", say.

While I was thinking what a PITA it would be to do anything about the Debian package in question, Tim just ran one command on each machine and solved the problem in a way that works no matter what causes the mail:

# Set a Linux box's root user's "full name" to identify
# them as root of this particular machine.
sudo chfn -f "`hostname -s` root"

If you have any Mac OS boxes, you'll need something like this instead, to go via NetInfo:

# Set a Mac OS box's root user's "full name" to identify
# them as root of this particular machine.
sudo niutil -createprop / /users/root realname "`hostname -s` root"

It's not as useful at home as at work (unless you have as many machines at home as you do at work), but it's better than a kick in the plums.

(Tuncer Ayaz suggests nullmailer (which you can "apt-get install") for all your mail relaying needs, and says that it defaults to including the hostname in mail from root. Sadly, my mail situation's currently a bit complicated for that, but it's something to look into.)