VMware ESXi and vSphere Cluster Management
Redirect Local Email with Linux Mail Aliases
Learn how Linux mail aliases redirect root and other local mail to users or files using Sendmail, Postfix, and newaliases.
An email alias is a local recipient mapping. It lets one local name stand for another destination, so mail addressed to root can be delivered to a local administrator account or a file.
This lesson covers aliases on systems using Sendmail, Postfix, or compatible mail transfer agents (MTAs). An MTA is mail server software that routes and delivers messages.
Why Redirect Root Mail?
The root account is intended for system administration, not routine interactive use. Regular work should normally be performed from an ordinary account with privilege escalation when needed. This reduces the chance that a mistake affects the entire system and makes administrative activity easier to audit.
System services, scheduled tasks such as cron jobs, package tools, and administrative programs may still send reports, warnings, and failure messages to root. If nobody regularly reads root's mailbox, important local notifications can be missed.
Redirecting root mail to an administrator's ordinary local account helps ensure that these messages are seen without requiring routine root login.
How Local Email Aliases Work
A local recipient is a mailbox name handled by the local host's mail system, such as root or bob. An alias maps that name to one or more delivery destinations.
Aliases are generally intended for locally addressed mail. They are not a general-purpose mechanism for rewriting arbitrary remote addresses such as recipients on unrelated Internet domains.
The basic entry format is:
local_alias_name: destinationThe name on the left is the local recipient name being matched. The destination on the right is where the mail should be delivered. Multiple destinations can be listed when more than one copy is required.
Finding the Aliases File
The aliases text file is commonly located at one of these paths:
/etc/aliases/etc/mail/aliases
The correct path depends on the installed MTA and the distribution's configuration. Use the path configured by the system rather than assuming that both files are active.
Redirect Root Mail to a Local User
To send locally addressed mail for root to the local user bob, add this entry to the active aliases file:
root: bobHere, root is the left-hand alias name and bob is the right-hand local delivery target. A message addressed locally to root is expanded and delivered to Bob's local mailbox.
After editing the file, rebuild the alias database when required:
newaliasesSome MTAs read the text file through a generated lookup database instead of parsing the text file for every delivery. In that case, editing the text file alone does not activate the change. Sendmail and Postfix-compatible alias handling commonly use newaliases or an equivalent database-building step.
Common Alias Destinations
Deliver Mail to a Local File
An alias destination may be a file path. For example:
bob: /home/bob/bobs_mail_backupThis tells the local mail system to write messages addressed to bob to /home/bob/bobs_mail_backup instead of, or according to the MTA's alias semantics, delivering them to Bob's normal mailbox.
File delivery is useful for local archival or backup storage, but the mail delivery process must have permission to access the parent directory and write to the destination file. Verify ownership, mode bits, and any applicable security policy before relying on this configuration.
Use file destinations carefully:
- Protect the file from unauthorized reading because mail may contain sensitive information.
- Ensure the parent directory exists and is accessible to the mail delivery process.
- Monitor file size because messages may accumulate indefinitely.
- Define rotation, retention, or archival procedures.
- Check logs for permission-denied, invalid-path, or other delivery failures.
For some workloads, normal mailbox delivery may be safer and easier to manage than an ever-growing plain file.
Safe Administration Workflow
- Identify the installed MTA and the aliases file it uses.
- Back up the existing aliases file or preserve its contents in version-controlled system administration records.
- Inspect existing standard aliases before making changes. Do not remove distribution-provided entries without understanding their purpose.
- Add the required mapping, such as
root: bob. - Run
newaliasesif the MTA uses a generated alias database. - Send a local test message addressed to the aliased recipient.
- Inspect the intended user's mailbox or the configured backup file.
- Review mail logs if delivery, expansion, or file writing does not work.
A local test can be sent with a command-line mail client when one is installed:
mail -s "Alias test" rootAfter sending, check Bob's mailbox for the message. If using file delivery, inspect the configured file and confirm that a new message was appended.
Understanding the Update Step
The aliases file is a human-readable configuration file. An alias database is a generated lookup database built from that file by mail software that requires compiled lookups.
The normal sequence is:
edit /etc/aliases or /etc/mail/aliases
newaliasesThe exact editor command and active file vary by system. The important point is that newaliases must be run after editing whenever the installed MTA does not read the text file directly for each delivery.
Troubleshooting Alias Delivery
Alias changes have no effect
- Confirm that you edited the aliases file used by the installed MTA.
- Run
newaliasesafter editing when applicable. - Review the MTA configuration to confirm that aliases are enabled and that the expected file is configured.
- Inspect the system's mail logs for alias lookup or delivery errors.
Root mail does not arrive for the intended user
- Verify that the target local username exists and can receive mail.
- Check that the entry has a colon separating the alias name and destination.
- Look for spelling errors or unsupported syntax.
- Send a new local test message and inspect the mail logs.
- Confirm that local mail delivery itself is working independently of the alias.
File delivery does not work
- Verify that the path exists or that the MTA is allowed to create the file.
- Check write and search permissions on the file and every parent directory.
- Check security policy and filesystem restrictions.
- Use an approved local path appropriate for mail delivery.
- Search logs for permission-denied or delivery-specific errors.
The backup file grows unexpectedly
A file destination retains every delivered message. Monitor its size and establish rotation or retention rules. If indefinite retention is not required, use a mailbox or managed archival process instead.
Exam-Relevant Notes
- An email alias maps one local recipient name to one or more delivery destinations.
- The left side of an entry is the local alias name; the right side is the delivery target.
/etc/aliasesand/etc/mail/aliasesare common aliases file locations.root: bobredirects locally addressed root mail to the local user Bob.- Multiple destinations can receive copies of one message.
- A file destination requires safe permissions and ongoing growth management.
newaliasesrebuilds the generated alias database when the MTA requires it.- Logs and a local test message are essential when diagnosing alias delivery.
For related guidance, see Redirect Email.