Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
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.
/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
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.
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.
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.
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.