Securing ISPConfig 3.1 With a Free Let's Encrypt SSL Certificate

Author: ahrasis

This tutorial shows how to create and configure a free Let's encrypt SSL certificate for the ISPconfig interface (port 8080), the email system (Postfix and Dovecot/Courier), the FTP server (pure-ftpd) and Monit. The commands in this tutorial have been tested on Ubuntu 16.04, they should work for Debian as well. Certain modifications may be necessary to make it work on CentOS.

Help on this guide is available in this forum thread.

Creating A Website Using ISPConfig Server Hostname FQDN

Create a site for your server in ISPConfig panel via Sites > Website > Add new website. Remember! This is your server website and as such it must contain your server fully qualified domain name (FQDN). I will refer to it as `hostname -f` in this guide.

hostname -f

Hopefully, it will work without any changes to your server as well.

Accessing ISPConfig Website Online

Check if your server site is ready and accessible online as Let's Encrypt needs to verify your website is accessible before issuing SSL key, certificate and chain file for your server site. You also have to create its DNS zone and allow it to properly propagate as Let's Encrypt needs to verify it too.

Enabling SSL For ISPConfig 3 Control Panel (Port 8080)

If you haven't enabled SSL during ISPConfig setup i.e. for its control panel at port 8080, enable it by typing ispconfig_update.sh in the terminal and select yes for SSL. We don't need this to be a proper key nor do we want to keep it but we want to work faster, thus we can simply enter for all of its fields. When you finished this, the self-signed SSL should already be enabled for your ISPConfig.

Checking SSL For ISPConfig 3 Control Panel (Port 8080)

Check your browser to confirm by opening ISPConfig control panel at port 8080. Note that you might get some warning at this stage since the created SSL files are self-signed but the browser will confirm that your ISPConfig has SSL enabled or otherwise.

Securing ISPConfig Website With Let's Encrypt SSL

If the above is done, go back to ISPConfig panel > Sites > Website > Website Name, then click SSL and Let's Encrypt check buttons and save - to create Let's Encrypt SSL files and enable them for your server site. If successful your server site shall now be using this Let's Encrypt SSL files but not your ISPConfig 8080 page. If unsuccessful, you will not be able to proceed further, so do check its log file for a clue.

Changing ISPConfig 3 Control Panel (Port 8080)

If LE SSL is already working, then go to your server terminal, go root via sudo su and use the following command to backup and replace the created self-signed SSL files with Let's Encrypt SSL files.

cd /usr/local/ispconfig/interface/ssl/
mv ispserver.crt ispserver.crt-$(date +"%y%m%d%H%M%S").bak
mv ispserver.key ispserver.key-$(date +"%y%m%d%H%M%S").bak
mv ispserver.pem ispserver.pem-$(date +"%y%m%d%H%M%S").bak
ln -s /etc/letsencrypt/live/$(hostname -f)/fullchain.pem ispserver.crt
ln -s /etc/letsencrypt/live/$(hostname -f)/privkey.pem ispserver.key
cat ispserver.{key,crt} > ispserver.pem
chmod 600 ispserver.pem

  • If you haven't created ispserver.pem before, you may ignore the third line which is aimed at renaming the existing one, if any, as a backup.
  • ote that we are using Let's Encrypt live folder instead of archive folder.
  • Also note the last line where ispserver.pem is created by combining files, thuswise, it will not be automatically renewed by Let's Encrypt unlike other files which we merely symlinked them, thus, we will deal with this in the last part of this guide.
  • Note also that you either type in `hostname -f` or server1.example.com as the result is the same because `hostname -f`is server1.example.com.

Using The Same Let's Encrypt SSL Certs For Other Major Services

As additional tips, based on Securing Your ISPConfig 3 Installation you may want to use symlink to ispserver.key or .crt or .pem instead of directly pointing your postfix, dovecot, courier, pure-FTPd and monit to Let's Encrypt SSL files. For dovecot, if it is already using postfix SSL files, it is safe for you to ignore it. In details you only need to do the followings:

a. For Postfix

cd /etc/postfix/
mv smtpd.cert smtpd.cert-$(date +"%y%m%d%H%M%S").bak
mv smtpd.key smtpd.key-$(date +"%y%m%d%H%M%S").bak
ln -s /usr/local/ispconfig/interface/ssl/ispserver.crt smtpd.cert
ln -s /usr/local/ispconfig/interface/ssl/ispserver.key smtpd.key
service postfix restart
service dovecot restart


b. For dovecot: (* Note this shouldn't exist together with courier)

Check if this code exist by using nano /etc/dovecot/dovecot.conf

[...]
ssl_cert = </etc/postfix/smtpd.cert
ssl_key = </etc/postfix/smtpd.key
[...]

Leave them as they are if they exist. Otherwise, fix them. In any event, run service dovecot restart is already covered above.

c. For courier: (* Note this shouldn't exist together with dovecot)

cd /etc/courier/
mv imapd.pem imapd.pem-$(date +"%y%m%d%H%M%S").bak
mv pop3d.pem pop3d.pem-$(date +"%y%m%d%H%M%S").bak
ln -s /usr/local/ispconfig/interface/ssl/ispserver.pem imapd.pem
ln -s /usr/local/ispconfig/interface/ssl/ispserver.pem pop3d.pem
service courier-imap-ssl stop
service courier-imap-ssl start
service courier-pop-ssl stop
service courier-pop-ssl start

d. For pure-FTPd:

cd /etc/ssl/private/
mv pure-ftpd.pem pure-ftpd.pem-$(date +"%y%m%d%H%M%S").bak
ln -s /usr/local/ispconfig/interface/ssl/ispserver.pem pure-ftpd.pem
chmod 600 pure-ftpd.pem
service pure-ftpd-mysql restart

e. For monit: (If you have it installed in your server)

nano /etc/monit/monitrc

Add the above symlink to ispserver.pem we created for pure-ftpd in here as well:

[...]
set httpd port 2812 and
SSL ENABLE
PEMFILE /etc/ssl/private/pure-ftpd.pem
allow admin:'secretpassword'
[...]

And restart monit:

service monit restart


Create Auto Renewal Script For Your ISPConfig Pem File (ispserver.pem)

In this last step, which I haven't found in any guide so far, is the automatic update of ispserver.pem as earlier hinted. Currently, it have to be manually changed right after Let's Encrypt automatically renewed your server SSL files. To avoid overlooking this, you may want to install incron as suggested in the respective incron tutorial and create a script to automatically update your ispserver.pem file, as follows:

Via terminal command, install incron, then create the script file and edit it using nano:

apt install -y incron
nano /etc/init.d/le_ispc_pem.sh

Add this in the le_ispc_pem.sh:

#!/bin/sh
### BEGIN INIT INFO
# Provides: LE ISPSERVER.PEM AUTO UPDATER
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: LE ISPSERVER.PEM AUTO UPDATER
# Description: Update ispserver.pem automatically after ISPC LE SSL certs are renewed.
### END INIT INFO
cd /usr/local/ispconfig/interface/ssl/
mv ispserver.pem ispserver.pem-$(date +"%y%m%d%H%M%S").bak
cat ispserver.{key,crt} > ispserver.pem
chmod 600 ispserver.pem
chmod 600 /etc/ssl/private/pure-ftpd.pem
service pure-ftpd-mysql restart
service monit restart
service postfix restart
service dovecot restart
service nginx restart
  • Note some people do not install monit, so they can safely remove it. Do adjust the above script accordingly.
  • For multi-server setup, do refer to post #203 and add the given scp code in here to automate future update.

We then make it executable, add root as an allowed user for incrontab and then edit incrontab file:

chmod +x /etc/init.d/le_ispc_pem.sh
echo "root" >> /etc/incron.allow
incrontab -e


Add this line in it incrontab:

/etc/letsencrypt/archive/$(hostname -f)/ IN_MODIFY ./etc/init.d/le_ispc_pem.sh

Restarting Your Services

I think that is about it for Securing Your Server With Let's Encrypt. You may want to restart your web server afterwards.

service nginx restart

Remember: if you are using apache, change nginx to apache2 accordingly.

LE4ISPC

As an alternative, you might want to use LE4ISPC script created for this purpose which supports both nginx and apache2 from ISPConfig up to pure-ftpd above except for monit. Before using it, you should already have completed the above steps (1-5) and have :

1. Created the website for your server via ISPConfig;
2. The website accessible online;
3. ISPConfig SSL enabled (via installation or update);
4. LE SSL successfully enabled for the website.

Share this page:

Suggested articles

15 Comment(s)

Add comment

Comments

From: fsisti at: 2018-02-14 09:08:05

Thank you for the tutorial

How can I test if the auto-renew script renewal works well?With the icrontab -l command I get this, is it correct?

/etc/letsencrypt/archive/$(hostname 0 IN_MODIFY ./etc/init.d/le_ispc_pem.sh

From: Marc at: 2018-02-15 22:13:19

Thanks for this tutorial.

I’ve a suggestion. Instead of symlinking '/etc/letsencrypt/live/…' one should symlink the SSL certs in the SSL folder of the website ('/var/www/clients/clientX/webY/ssl/…') as Till suggests here:

https://git.ispconfig.org/ispconfig/ispconfig3/issues/4589#note_62298

Problem is that the LE path can change under some circumstances described in the issue mentioned above.

From: Tom Dings at: 2018-02-17 12:16:22

Thanks. Really interesting piece of information. May I ask how you will do the 'trick' when the setup of IspConfig is done with more than one server ?First thought ... Copying the same certificates to the other servers I guess ? Requesting new ones isn't a good idea I guess. Really like to know how to solve such a setup. Enjoy your weekend!

From: ludo at: 2018-02-17 14:28:05

Thank for this tutorial. And for the auto-renew script!

How can I add mail subdomain (mail.domain.tld) in the LE certificate. At this time, I have only domain.tld and www.domain.tld in the LE certificate, accroding to: openssl x509 -in /etc/letsencrypt/live/domain.tld/fullchain.pem -noout -text

From: onastvar at: 2018-02-19 05:36:15

Will my clients need to update their email settings on their devices if I was to install SSL on my server. It says in description: "This tutorial shows how to create and configure a free Let's encrypt SSL certificate for the ISPconfig interface (port 8080), the email system (Postfix and Dovecot/Courier), the FTP server (pure-ftpd) and Monit."?

From: ustoopia at: 2018-03-19 19:37:03

Very usefull! Thanks for this great tutorial!

From: Keldan at: 2018-04-15 15:15:39

Hi !

Good Job, but there is an error in syslog for pure-ftpd. pure-ftpd-dhparams.pem is missing.

So, add ln -s /etc/ssl/private/pure-ftpd.pem /etc/ssl/private/pure-ftpd-dhparams.pem and service pure-ftpd-mysql restart.

Thx

From: Bjoern at: 2018-07-11 12:24:10

Or use after ln -s /usr/local/ispconfig/interface/ssl/ispserver.pem pure-ftpd.pem:

 

openssl dhparam -out /etc/ssl/private/pure-ftpd-dhparams.pem 2048

and restart

service pure-ftpd-mysql restart

From: SamTzu at: 2018-04-20 13:31:43

#These lines work better as a script for a generate-ispconfig-ssl.sh

cd /usr/local/ispconfig/interface/ssl/mv ispserver.crt ispserver.crt-$(date +"%y%m%d%H%M%S").bakmv ispserver.key ispserver.key-$(date +"%y%m%d%H%M%S").bakmv ispserver.pem ispserver.pem-$(date +"%y%m%d%H%M%S").bakln -s /etc/letsencrypt/live/$(hostname -f)/fullchain.pem ispserver.crtln -s /etc/letsencrypt/live/$(hostname -f)/privkey.pem ispserver.keycat /usr/local/ispconfig/interface/ssl/ispserver.key > /usr/local/ispconfig/interface/ssl/ispserver.pemcat /usr/local/ispconfig/interface/ssl/ispserver.crt >> /usr/local/ispconfig/interface/ssl/ispserver.pemchmod 600 ispserver.pem

From: SamTzu at: 2018-04-20 14:18:31

Great job putting all of this together. Thx. PS. Remember always to use full paths on scripts.

From: cmd74 at: 2018-04-20 16:54:45

apache2 cannot restart after following this. I will note I dont have ispserver.pem

From: till at: 2018-04-20 17:11:35

Then you missed some commands from the tutorial, the file gets created in these lines:

cd /usr/local/ispconfig/interface/ssl/
.....

cat ispserver.{key,crt} > ispserver.pem
chmod 600 ispserver.pem

From: mixonic at: 2018-04-22 13:41:25

OS: Debian 9 Stretch

ISP version: 3.1.11

Hi,

first of all thanks for tut  :) .

I have some issues with instalation LE for my ISP CP ... I followed this guide for ISP installation, and also I installed self signed cert during setup. I created website exact as my server hostname (btw. its the first site in my ISP) as you said, but when I check in browser I get only Apache page, also when I check SSL an LE flags they disappear after ISP page refresh.

LE was installed with this command: sudo apt-get install python-certbot-apache -t stretch-backports

and command sudo certbot --authenticator webroot --installer apache

at step when ask which names would you like to activate HTTPS for I press c just to activate LE, later with same command above I try to install cert for server website. At step input webroot I put /var/www/clients/client1/web1/web regulary, but after that I get error:

Failed authorization procedure. ---.com (http-01): urn:acme:error:connection :: The server could not connect to the client to verify the domain :: Fetching http://---/.well-known/acme-challenge/uCeBBgn4hIBBL_6c741y2OAtLxne6ij-o8Xncftu-ik: Timeout after connect (your server may be slow or overloaded)

 

IMPORTANT NOTES:

 - The following errors were reported by the server:

 

   Domain:---

   Type:   connection

   Detail: Fetching

   http://---/.well-known/acme-challenge/uCeBBgn4hIBBL_6c741y2OAtLxne6ij-o8Xncftu-ik:

   Timeout after connect (your server may be slow or overloaded)

 

   To fix these errors, please make sure that your domain name was

   entered correctly and the DNS A/AAAA record(s) for that domain

   contain(s) the right IP address. Additionally, please check that

   your computer has a publicly routable IP address and that no

   firewalls are preventing the server from communicating with the

   client. If you're using the webroot plugin, you should also verify

   that you are serving files from the webroot path you provided.

 

Any help please :)

 

 

From: Ed at: 2018-05-06 07:24:08

Hello, after following this tutorial, I get an IDS (intrusion detection alert). Is this because I have added the incron user? IS there anything I should do, like re-run the IDS script?

 

Thanks

From: Poliman at: 2018-05-08 06:08:32

I was looking for the solution of providing auto renewal for ispserver.pem file without install any additional software. I perform some script, which after add to cron checks date of fullchain.pem and privkey.pem and compare them to default values. These default values each user has to set on his own for privkey.pem and fullchain.pem from convert their dates (enter directory /etc/letsencrypt/live/s1.example.net/ and simple "ls -l") to epoch format using for example https://www.epochconverter.com/:

#!/bin/bash#This script is developed for renewing cert used by Monit and other applications,#which will have provided Let's Encrypt certs#add to cronjob each midnight#epoch format of .key and .crt files - user need to configure this manuallyepoch_ispcrt_default=1520924890epoch_ispkey_default=1520924890ispcrt_date_current=`stat -c "%y" /etc/letsencrypt/live/s1.poliman.net/fullchain.pem`ispkey_date_current=`stat -c "%y" /etc/letsencrypt/live/s1.poliman.net/privkey.pem`#epoch format for current files modification datesepoch_ispcrt=`date -d "$ispcrt_date_current" +%s`epoch_ispkey=`date -d "$ispkey_date_current" +%s`#left value has to be greater than right valueif [ $epoch_ispcrt -gt $epoch_ispcrt_default ] && [ $epoch_ispkey -gt $epoch_ispkey_default ]then    $epoch_ispcrt_default=$epoch_ispcrt    $epoch_ispkey_default=$epoch_ispkey        cd /usr/local/ispconfig/interface/ssl        if [ -f "ispserver.pem" ]    then        mv ispserver.pem ispserver.pem-`date +"%y-%m-%d-%H:%M:%S"`.bak    fi        cat ispserver.{key,crt} > ispserver.pem    chmod 600 ispserver.pem        #restarting required services    service monit restartelse    #log_file.log will be created in path /usr/local/ispconfig/interface/ssl    echo "Log-->$(date +%y-%m-%d-%H:%M:%S) Compare thinks that variables are even or less, so we don't have to do anything with ispserver.pem." >> log_file.logfi