Dovecot refuses to start: Can't load SSL certificate, no valid PEM certificate
Can't load SSL certificate (ssl_cert setting): There is no valid PEM certificateShort answer
Dovecot reads the ssl_cert setting as the file's contents, not a path, so in 2.3 the value must start with a less-than sign. After that, the file must start with your server certificate and then the intermediates. Dovecot 2.4 uses new setting names that take a plain path. Match the config to your version.
Fix it fast
1Find out which cause you have
Print the settings Dovecot really uses and check how the certificate value is written, then ask which version you run.
doveconf -n | grep -E '^ssl' dovecot --version2Match what you see, then jump to its fix
- 1
ssl_cert = /etc/ssl/certs/mail.example.com.crt in doveconf -n, with no leading <The path in ssl_cert has no less-than sign (Dovecot 2.3)Fix - 2
The file opens, but it holds only an intermediate CA, or the intermediates come firstThe certificate file does not start with your server certificateFix - 3
dovecot --version says 2.4 while your files use ssl_cert and ssl_key, or the reverseA 2.3 configuration is used on Dovecot 2.4, or the other way roundFix
- 1
What does the error look like?
Can't load SSL certificate (ssl_cert setting): There is no valid PEM certificatedoveconf: Error: ssl enabled, but ssl_cert not setIMAP and POP3 logins fail with a TLS error after you changed the certificate
Cause 1 of 3
The path in ssl_cert has no less-than sign (Dovecot 2.3)
1Check
In Dovecot 2.3 the value holds the contents of the file. The docs say the less-than sign is mandatory and that leaving it out causes an error. Look at the line in your config.
grep -R -nE '^\s*ssl_(cert|key)' /etc/dovecot/2Fix
Add the sign directly before the path in both ssl_cert and ssl_key.
ssl_cert = </etc/ssl/certs/mail.example.com.crt
ssl_key = </etc/ssl/private/mail.example.com.key3Verify
Reload Dovecot and watch the log for the error to be gone.
sudo systemctl reload dovecot
sudo journalctl -u dovecot -n 20 --no-pagerConfirmed by doc.dovecot.org
Cause 2 of 3
The certificate file does not start with your server certificate
1Check
The Dovecot docs say the ssl_cert file must contain the server certificate first, then each signing CA in order. Print the subject of the certificate OpenSSL reads from the file; it should be your mail host name.
openssl x509 -in /etc/ssl/certs/mail.example.com.crt -noout -subject2Fix
Rebuild the file in the right order: your certificate, then the intermediates, or use the full-chain file your certificate provider gives you.
cat mail.example.com.crt intermediate.crt > /etc/ssl/certs/mail.example.com.fullchain.crt3Verify
Point ssl_cert at the combined file, reload, and test the handshake.
openssl s_client -servername mail.example.com -connect mail.example.com:imapsConfirmed by doc.dovecot.org
Cause 3 of 3
A 2.3 configuration is used on Dovecot 2.4, or the other way round
1Check
The 2.4 documentation writes the settings as ssl_server_cert_file and ssl_server_key_file with a plain path, with no less-than sign. Compare your file with the documentation for the version that is installed.
dovecot --version2Fix
Write the certificate settings in the style of your installed version. For 2.4:
ssl_server_cert_file = /etc/dovecot/dovecot.crt
ssl_server_key_file = /etc/dovecot/dovecot.key3Verify
Check that doveconf accepts the file with no errors, then reload.
doveconf -n > /dev/null
sudo systemctl reload dovecotConfirmed by doc.dovecot.org
How do I stop it coming back?
- Keep the key readable only by root; the Dovecot docs prefer root:root 0400 for the key file.
- After every renewal, run doveconf -n and an openssl s_client test before you walk away.
- Note the Dovecot version next to the config in your server notes, so the right documentation is used.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Postfix refuses to send with "Relay access denied"
454 4.7.1 <user@example.net>: Relay access denied
Postfix says Relay access denied when a client asks it to deliver to a domain it does not host, and the client is neither listed in mynetworks nor logged in with SASL.
5 causes, each with a fixMail from your own domain keeps landing in the spam folder
dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=example.com
Open a message that went to spam and read its Authentication-Results header: it shows whether SPF, DKIM and DMARC passed, and for which domain.
5 causes, each with a fixOutlook.com bounces your mail with 550 5.7.515
status=bounced (host hotmail-com.olc.protection.outlook.com[...] said: 550 5.7.515 Access denied
550 5.7.515 means Outlook.com counts your From domain as a high-volume sender (5,000 or more messages a day to Microsoft consumer addresses) and the message failed its authentication rules.
4 causes, each with a fixSpamAssassin adds SPF_HELO_NONE to mail sent from your Postfix server
X-Spam-Status lists SPF_HELO_NONE even though SPF for your From domain passes
The receiver checked SPF for the name your server gave in HELO and found no record.
2 causes, each with a fixDjango send_mail fails or hangs with an SSL error
smtplib.SMTPException raised from send_mail()
Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).
4 causes, each with a fixJakarta Mail throws MessagingException: Could not convert socket to TLS
javax.mail.MessagingException: Could not convert socket to TLS
The server accepted STARTTLS, but the TLS handshake that followed failed on your side.
3 causes, each with a fix