Redirect email

You can use email aliases to enable one email address to stand in for another one. For example, since reading mail as root is not advisable because of the security reasons, you may want to set up an alias and link the root name to the name of a user account. This will redirect all of root’s mail to that user account.

Aliases are defined in the aliases file, which usually resides in /etc or /etc/mail:

linux aliases file

Aliasing occurs only on local names.


To define an alias, simply add a line that contains a local name and the name of a local account to which the messages are forwarded:

linux defining mail alias

In the example above we have redirected all of root’s mail to the user bob.

Some mail servers (such as Sendmail and Postfix) require you to compile the aliases file into a binary file each time you change the content of this file. To do so, use the newaliases command.


You can also define an additional local file in which messages will be stored. For example, to store all emails sent to bob to the /home/bob/bobs_mail_backup file, you can use the following command:

linux aliases mail backup

Geek University 2022