1. Overview

In Linux, files are essential for system configuration and management. One such file is /etc/aliases, which helps simplify email management. This is possible since it defines aliases responsible for determining the destination of incoming mail.

In this tutorial, we aim to figure out the /etc/aliases file.

2. Exploring the /etc/aliases File

/etc/aliases is a configuration file. It assists the mail transfer agent (MTA) in mapping aliases to local user accounts or external email addresses. By default, each line in this file consists of two components:

alias: destination_address
  • alias – Refers to the custom email address to which incoming email messages are sent. It can be a custom name that doesn’t necessarily refer to a valid system account.
  • destination_address – Represents where the email messages sent to the alias should be forwarded to. Moreover, we can add multiple destination addresses separated by commas.

In detail, when the MTA receives an email sent to an email alias, it first turns to the /etc/aliases file. Here, it requests the corresponding destination address and then sends the email to that location.

It’s important to note that we can use the # symbol at the beginning of a line to add comments to our file. These comments present a helpful way to document the aliases.

3. Updating the /etc/aliases File

We can use a text editor like nano to introduce a new alias to the /etc/aliases file:

# /etc/aliases
postmaster: root

On save, any email addressed to the alias postmaster should now go to the local user root. However, this doesn’t happen unless we update the system’s alias database:

$ sudo newaliases

The newaliases command reads the /etc/aliases file and generates a new alias database. This database is where the MTA searches for aliases when processing incoming emails.

4. Practical Applications

First, the /etc/aliases file enables us to create a mailing list. Mailing lists allow sending emails to multiple recipients. For example, we can define a mailing list known as marketing that includes all members of a particular department:

marketing: [email protected], [email protected], [email protected]

Now, any email sent to the alias marketing will be sent to the three listed external emails.

Secondly, we can use this file for email forwarding:

support: [email protected]

Here, [email protected] receives email messages sent to the support alias.

Finally, the /etc/aliases file helps us associate system accounts with email addresses. For instance, we can redirect all system-generated emails meant for the root user to the system administrator’s email. This way, the administrator stays informed about any potential issues:

root: [email protected]

Above, messages are now sent to [email protected], the administrator’s email.

5. Conclusion

In this article, we described the /etc/aliases file as well as its contents. Then, we explored how to update the file. Later, we discussed its practical applications.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.