Can’t load private ssl_key: Key is for a different cert than ssl_cert

Проблема возникает при проблемах настройки сертификата для почтового сервера. В логах содержаться ошибки следующего содержания:

# tail -5 /var/log/mail
Jul 09 07:36:43 ***** dovecot[862]: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul 09 07:36:43 ***** dovecot[764]: master: Error: service(imap-login): command startup failed, throttling for 2 secs
Jul 09 07:37:31 ***** dovecot[862]: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul 09 07:37:31 ***** dovecot[764]: master: Error: service(imap-login): command startup failed, throttling for 4 secs
Jul 09 07:38:51 ***** dovecot[862]: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert

Вывод журнала systemd:

# journalctl -b -u dovecot
Jul  9 08:30:23 ***** dovecot: pop3-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:30:23 ***** dovecot: master: Error: service(pop3-login): command startup failed, throttling for 2 secs
Jul  9 08:30:25 ***** dovecot: pop3-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:30:25 ***** dovecot: master: Error: service(pop3-login): command startup failed, throttling for 4 secs
Jul  9 08:30:25 ***** dovecot: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:30:25 ***** dovecot: master: Error: service(imap-login): command startup failed, throttling for 2 secs
Jul  9 08:30:27 ***** dovecot: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:30:27 ***** dovecot: master: Error: service(imap-login): command startup failed, throttling for 4 secs
Jul  9 08:34:56 ***** dovecot: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:34:56 ***** dovecot: master: Error: service(imap-login): command startup failed, throttling for 8 secs
Jul  9 08:46:12 ***** dovecot: pop3-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:46:12 ***** dovecot: master: Error: service(pop3-login): command startup failed, throttling for 8 secs
Jul  9 08:46:20 ***** dovecot: pop3-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:46:20 ***** dovecot: master: Error: service(pop3-login): command startup failed, throttling for 16 secs
Jul  9 08:46:21 ***** dovecot: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:46:21 ***** dovecot: master: Error: service(imap-login): command startup failed, throttling for 16 secs
Jul  9 08:46:37 ***** dovecot: imap-login: Fatal: Can't load private ssl_key: Key is for a different cert than ssl_cert
Jul  9 08:46:37 ***** dovecot: master: Error: service(imap-login): command startup failed, throttling for 32 secs

Для начала выводим конфигурацию dovecont:

doveconf -n

Нас интересует расположение сертификата и ключа:

ssl_cert = </etc/exim/ssl/exim.crt
ssl_key = </etc/exim/ssl/exim.key

Переходим в указанный каталог:

cd /etc/exim/ssl/

Генерируем самоподписанный сертификат:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout exim.key -out exim.crt

Перезапустим exim и dovecot:

service dovecot restart
service exim restart