LinuxTutorialsUbuntu

How To Install Postfix on Ubuntu 20.04 LTS

Install Postfix on Ubuntu 20.04

In this tutorial, we will show you how to install Postfix on Ubuntu 20.04 LTS. For those of you who didn’t know, Postfix is a free and open-source MTA (Mail Transfer Agent) used for routing or delivering emails on a Linux system. By the default configuration it permits local mailing, however in itself it is very useful on a machine used by many customers, or even if there may be no such visitors, many services dump their reviews and messages into e-mails, which is introduced to the root consumer locally, so the sysadmin might be noticed on any activities when he/she logs in and switches to root user.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Postfix mail on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, you can harm your system if you’re not careful when acting as the root.

Install Postfix on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Postfix on Ubuntu 20.04.

Now we proceed with the installation of Postfix by running the following command:

sudo apt install postfix sasl2-bin

Now you will be prompted to choose the type of your Mail Server Configuration. Select proceed to select [No Configuration] from that list and press the Enter key as highlighted in the following image:

+------+ Postfix Configuration +-------+
| General type of mail configuration:  |
|                                      |
|       No configuration               |
|       Internet Site                  |
|       Internet with smarthost        |
|       Satellite system               |
|       Local only                     |
|                                      |
|                                      |
|       <Ok>           <Cancel>        |
|                                      |
+--------------------------------------+

Step 3. Configuring Postfix.

Once successfully installed, Now we edit the Postfix configuration file:

cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
nano /etc/postfix/main.cf

Add the following lines:

# line 78: uncomment

mail_owner = postfix

# line 94: uncomment and specify hostname

myhostname = mail.idroot.us

# line 102: uncomment and specify the domain name

mydomain = idroot.us

# line 123: uncomment

myorigin = $mydomain

# line 137: uncomment

inet_interfaces = all

# line 185: uncomment

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# line 228: uncomment

local_recipient_maps = unix:passwd.byname $alias_maps

# line 270: uncomment

mynetworks_style = subnet

# line 287: add your local network

mynetworks = 127.0.0.0/8,10.0.0.0/24

# line 407: uncomment

alias_maps = hash:/etc/aliases

# line 418: uncomment

alias_database = hash:/etc/aliases

# line 440: uncomment

home_mailbox = Maildir/

# line 576: comment out and add
# smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_banner = $myhostname ESMTP
# line 650: add

sendmail_path = /usr/sbin/postfix

# line 655: add

newaliases_path = /usr/bin/newaliases

# line 660: add

mailq_path = /usr/bin/mailq

# line 666: add

setgid_group = postdrop

# line 670: comment out
#html_directory =
# line 674: comment out
#manpage_directory =
# line 679: comment out
#sample_directory =
# line 683: comment out
#

readme_directory =

# line 684: if also listen IPv6, change to [all]

inet_protocols = ipv4

# add to the end
# for example, limit an email size to 10M
message_size_limit = 10485760
# for example, limit mailbox size to 1G
mailbox_size_limit = 1073741824

# SMTP-Auth settings
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject

Save the file and close it. To apply the changes, enter the command:

newaliases
sudo systemctl restart postfix

Congratulations! You have successfully installed Postfix. Thanks for using this tutorial for installing the Postfix on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Postfix website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button