Linux Postfix SMTP (Mail Server) SSL Certificate Installations and Configuration

In this tutorial you will learn about Installing SSL Certificate (Secure Server Certificate) to secure communication between Postfix SMTP server and mail client such as Outlook or Thunderbird.

You need to generate a CSR certificate for CA, to use with your Postfix mail server. This tutorial instuctions are tested under:


  1. Redhat enterprise Linux 5
  2. CentOS 5 Server
  3. FreeBSD 7 server

Procedure for creating a CSR on postfix MTA is just like web server. You need to use OpenSSL which is a cryptography toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) network protocols and related cryptography standards under Linux / UNIX. To configure postfix SSL SMTP you need 3 files

  • The private key generated using step #1
  • Your .crt certificate file (it will be send by CA)
  • CA certificate (also known as

Let us see how to create certificate for Postfix smtp server called

Step # 1: Generating a CSR and private key for Postfix SMTP

Type the command to create a SSL CSR for a mail server called
# mkdir /etc/postfix/ssl
# cd /etc/postfix/ssl
# openssl req -new -nodes -keyout -out

Most important is Common Name, in our example it is set to For the common name, you should enter the full mail server address of your site.

Sample output:

Generating a 1024 bit RSA private key
writing new private key to ''
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:MHA
Locality Name (eg, city) []:Pune
Organization Name (eg, company) [Internet Widgits Pty Ltd]:NIXCRAFT LTD
Organizational Unit Name (eg, section) []:ITDEPT
Common Name (eg, YOUR name) []
Email Address []

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:myPassword
An optional company name []:NIXCRAFT LTD

Step # 2: Submit CSR to CA

Now a CSR is generated. All you have to do is copy and paste the contents of the CSR file into the SSL certificate providers (aka CA) account. Never ever give out your private key or certificate to anyone. After verification you should receive a zip file with certificates.

Step # 3 : Install your SSL certificate

Unzip file and upload certificates to /etc/postfix/ssl directory.

Step # 4: Configure Postfix SMTP for SSL certificate

Open postfix smtp configuration file and append following directive:
smtpd_use_tls = yes
smtpd_tls_auth_only = yes
smtpd_tls_key_file = /etc/postfix/ssl/
smtpd_tls_cert_file = /etc/postfix/ssl/
smtpd_tls_CAfile = /etc/postfix/ssl/caroot.crt
smtpd_tls_loglevel = 1

smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

Save and close the file. Restart or reload postfix service
# postfix reload.
# /etc/init.d/postfix restart

Note I have SASL configured as follows in
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination, permit_mynetworks check_relay_domains
smtpd_delay_reject = yes
broken_sasl_auth_clients = yes

Test Postfix TLS (SSL)

In order to test the TLS, just telnet on port 25 (you must see STARTTLS and AUTH lines):
$ telnet 25

Connected to
Escape character is '^]'.
220 ESMTP Postfix
250-SIZE 10240000
250 DSN

And mail log file…
# tail -f /var/log/maillog

Jul 12 14:25:10 smtp postfix/smtpd[28817]: connect from unknown[]
Jul 12 14:25:11 smtp postfix/smtpd[28817]: setting up TLS connection from unknown[]
Jul 12 14:25:11 smtp postfix/smtpd[28817]: TLS connection established from unknown[]: TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)
Jul 12 14:25:12 smtp postfix/smtpd[28817]: B3A0A9D8443: client=unknown[], sasl_method=PLAIN,
Jul 12 14:25:13 smtp postfix/cleanup[28807]: B3A0A9D8443: message-id=<>
Jul 12 14:25:13 smtp postfix/qmgr[28806]: B3A0A9D8443: from=, size=632, nrcpt=1 (queue active)
Jul 12 14:25:14 smtp postfix/smtpd[28817]: disconnect from unknown[]
Jul 12 14:25:14 smtp postfix/smtp[28821]: B3A0A9D8443: to=,[]:25, delay=2.1, delays=1.5/0/0.13/0.49, dsn=2.0.0, status=sent (250 2.0.0 OK 1184268314 n29si21297786elf)
Jul 12 14:25:14 smtp postfix/qmgr[28806]: B3A0A9D8443: removed

You can use same SSL security certificates with dovecot secure IMAPS / POP3S server.

See also:

If you just need self signed postfix SSL certificate please see this tutorial for more information.

Updated for accuracy.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

16 comments… add one
  • BOK Jul 12, 2007 @ 21:28

    I was using Postfix with SASL before but it seems it’s not needed anymore: just compile in TLS.
    One this I get this warning on PF v2.4.3.1:

    warning: support for restriction "check_relay_domains" will be removed from Postfix; use "reject_unauth_destination" instead

    so it’s best to adapt that specific line, I guess…

  • BOK Jul 12, 2007 @ 21:40

    Oops… add this information too, since I forgot to mention I use SASL through Dovecot IMAP/POP-server:
    smtpd_sasl_type = dovecot
    smtpd_sasl_path = private/auth

  • Raj Jul 12, 2007 @ 21:41

    BOK says: just compile in TLS.

    How do I find out – my postfix is compiled with TLS? Any idea ????


  • BOK Jul 12, 2007 @ 21:53

    One is the maillog saying:
    warning: TLS has been selected, but TLS support is not compiled in
    Two is: wen using the above telnet-command to port 25 “STARTTLS” is missing.
    FYI: FreeBSD is offering me the option to complile Postfix with TLS and SSL when running “make config”.

  • 🐧 nixCraft Jul 13, 2007 @ 9:47


    Thanks I’ve old version, may be I will update tonight 🙂

  • Teja Aug 7, 2007 @ 10:38

    hi ,
    i have Redhat Linux Ent Ed. 4 and oracle Application Server 10g Release 2.
    I created the key using following commands.
    $ openssl genrsa -des3 -out vcb.key 1024
    $ openssl req -new -key vcb.key -out vcb.csr

    Now i got the certificate from the CA

    Please guide me how can i install the SSL.
    Abu Dhabi, UAE

  • Juha Vehnia Jan 27, 2009 @ 14:43

    In order to get this work you also must install Dovecot and enable SASL authentication server.

    yum install dovecot

    To enable authentication server, edit /etc/dovecot.conf and adding the following:

    auth default {
    mechanisms = plain login
    passdb pam {
    userdb passwd {
    socket listen {
    client {
    path = /var/spool/postfix/private/auth
    mode = 0660
    user = postfix
    group = postfix

    Finally restart dovecot IMAP server with the command:

    /etc/init.d/dovecot restart

  • Eranga Wasantha May 5, 2009 @ 7:59

    The error when testing the email is:
    Send Test Email Message: The specified server was found, but there was no response from the server. Please verify that the port and SSL information is correct. To access these settings close this dialogue, then click More Settings on the Advanced tab.

    Log Onto Incoming Mail Server (POP 3): The specified server was found, but there was no response from the server. Please verify that the port and SSL information is correct. To access these settings close this dialogue, then click More Settings on the Advanced tab.

  • Leonardo Jun 10, 2011 @ 20:31

    Hi, the certificate used for postfix is the same used on the webserver or is it a specific certificate for this?

  • Nate Jul 6, 2011 @ 15:03


    I have a question about securing the server-to-server communications with postfix. What needs to be done to force the use of TLS enabled connections?

  • pawan saini Oct 17, 2011 @ 16:41

    i am using postfix with SASL & TLS. the issue is when i telnet postfix server on port 25 it shows the follwing output

    220 ESMTP Postfix
    250-SIZE 10240000
    250 DSN

    1) why doesnt it show AUTH parameters???
    2) when i remove the TLS then it shows the AUTH parameter in EHLO???

  • david mark May 13, 2012 @ 1:44

    pls i need to insatalle smtp to be able to send millions of email in 5minuite i dont know how to installe cento5 or postix i need someone to help me out

  • Charlie Nielsen Jun 10, 2012 @ 23:09

    Please note that the above is considered unsecure now. You’ll need a key length of 2048 bits, so try this one instead:

    openssl req -nodes -newkey rsa:2048 -keyout -out

  • ugh Jul 30, 2013 @ 19:58

    “Open postfix smtp configuration file” is a massive tutorial fail because

    “golly, sure hope i pick the right file”

    “stfu noob, everybody knows its were you raised in a barn?”

  • AJ Feb 23, 2014 @ 13:41

    I followed your instructions but it seems I am not capable enough to make something like this. May I know if how can I remove the directory or files created sing this tutorial to reset or bring back postfix to its original setting files?

  • dxman Apr 1, 2014 @ 17:59

    my postfix is sending spam mails , mail queue is showing that from gmail or yahoo accounts are sending mail to their own email address , example , if email is then in mail.q it is like this
    from to

    please suggest what to do

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.