One place for hosting & domains


      How To Create Let’s Encrypt Wildcard Certificates with Certbot


      A wildcard certificate is an SSL certificate that can secure any number of subdomains with a single certificate. You may want a wildcard certificate in cases where you need to support multiple subdomains but don’t want to configure them all individually.

      Let’s Encrypt is an SSL certificate authority that grants free certificates using an automated API. In this tutorial you will create a Let’s Encrypt wildcard certificate by following these steps:

      1. Making sure you have your DNS set up correctly
      2. Installing the Certbot plugins needed to complete DNS-based challenges
      3. Authorizing Certbot to access to your DNS provider
      4. Fetching your certificates

      This information is intended to be useful for any Linux distribution and any server software, but you may have to fill in some gaps with further documentation, which we will link to as we go.


      This tutorial assumes you already have the following:

      • The Certbot utility installed, version 0.22.0 or later. If you need help installing Certbot, please visit our Let's Encrypt tag page, where you can find installation guides for a variety of Linux distributions and servers. Some common setups are listed below:
      • A domain name, and a DNS provider that is supported by Certbot. See Certbot’s DNS plugin list for a list of supported providers

      Let’s begin by setting up and testing our DNS records.

      Step 1 — Setting up Wildcard DNS

      Before we fetch our wildcard SSL certificate, we should make sure our server is responding to requests on multiple subdomains. This will typically be accomplished by setting up a wildcard DNS record, which looks similar to this:

      *   3600  IN  A

      The * wildcard character is treated as a stand-in for any hostname. This example DNS record would match, and It would not match the bare nor would it match because the * wildcard will only expand to one hostname, not to multiple levels of names.

      Additionally a wildcard DNS record can only have one wildcard character, so *.* is not allowed.

      Please refer to your DNS provider’s documentation to set up the correct DNS entries. You will want to add either an A or CNAME wildcard record before proceeding.

      Note: If you are using DigitalOcean to manage your DNS, please see How to Create, Edit, and Delete DNS Records in our product documentation for more information.

      To test that your wildcard DNS is working as intended, use the host command to query a few hostnames:

      Be sure to substitute your own domain and hostname above. Also, remember that it sometimes takes a few minutes for DNS records to propagate through the system. If you just added your DNS record and are getting errors, wait a few minutes and try again.

      When the hostname you entered resolves properly, you’ll output similar to the following:

      Output has address

      Otherwise, you’ll see an NXDOMAIN error:


      Host not found: 3(NXDOMAIN)

      Once you’ve verified that multiple subdomains are resolving to your server, you can continue on to the next step, where you’ll configure Certbot to connect to your DNS provider.

      Step 2 — Installing the Correct Certbot DNS Plugin

      Before issuing certificates, Let’s Encrypt performs a challenge to verify that you control the hosts you’re requesting certificates for. In the case of a wildcard certificate, we need to prove that we control the entire domain. We do this by responding to a DNS-based challenge, where Certbot answers the challenge by creating a special DNS record in the target domain. Let’s Encrypt’s servers then verify this record before issuing the certificate.

      In order to connect to your DNS provider, Certbot needs a plugin. Please see Certbot’s DNS plugin list to get the name of the appropriate plugin for your DNS provider.

      For instance, the DigitalOcean provider is called certbot-dns-digitalocean. We can install the certbot-dns-digitalocean plugin on Ubuntu and Debian by installing the following package:

      • sudo apt install python3-certbot-dns-digitalocean

      Other plugins should follow the same naming format. Swap your provider’s name into the command above if you’re using a different service.

      On CentOS and other RPM-based distributions the installation command may be dnf:

      • dnf install python3-certbot-dns-digitalocean

      Or yum:

      • yum install python3-certbot-dns-digitalocean

      You also may need to install additional package repositories on these distributions to get access to the Certbot plugin packages.

      To verify that the plugin was installed correctly, you can ask Certbot to list its current plugins:


      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * dns-digitalocean Description: Obtain certs using a DNS TXT record (if you are using DigitalOcean for DNS). Interfaces: IAuthenticator, IPlugin Entry point: dns-digitalocean = certbot_dns_digitalocean.dns_digitalocean:Authenticator * standalone Description: Spin up a temporary webserver Interfaces: IAuthenticator, IPlugin Entry point: standalone = certbot.plugins.standalone:Authenticator * webroot Description: Place files in webroot directory Interfaces: IAuthenticator, IPlugin Entry point: webroot = certbot.plugins.webroot:Authenticator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

      In the above output, the dns-digitalocean plugin is listed first, along with the default standalone and webroot plugins.

      When you have verified that the correct plugin is installed, continue on to the next step to configure it.

      Step 3 — Configuring the Certbot Plugin

      Because Certbot needs to connect to your DNS provider and create DNS records on your behalf, you’ll need to give it permission to do so. This involves getting an API token or other authentication information from your DNS provider, and putting it in a secure credentials file that Certbot will later read from.

      Because each provider has a different authentication process, please refer to the documentation for your particular Certbot DNS plugin for more information on what tokens or keys you’ll need to obtain.

      For this example, we will continue using the dns-digitalocean plugin, and will store our credentials in the file ~/certbot-creds.ini.

      We will create this file using the nano text editor:

      This will open up a new blank text file. You’ll want to add your information based on the instructions for your particular DNS provider. DigitalOcean requires a single API token, so it will look like this:


      dns_digitalocean_token = 235dea9d8856f5b0df87af5edc7b4491a92745ef617073f3ed8820b5a10c80d2

      Be sure to replace the example token above with your own information.

      Save and close the file. If you’re using nano, type CTRL+O (for “write out”), hit ENTER, then CTRL+X to exit.

      After creating the file, you will need to restrict its permissions so that your secret is not leaked to other users. The following chmod command will give read and write access to only your user:

      • chmod 600 ~/certbot-creds.ini

      Once you’ve set up your credentials file, you’re ready to actually request the certificate.

      Step 4 — Retrieving the Certificate

      At this point, retrieving your Let’s Encrypt wildcard certificate is similar to “normal” non-wildcard certificates. The main changes to the process are to specify the DNS-based challenge, and point to our DNS credentials file. Additionally we’ll use a wildcard domain with the -d flag:

      • sudo certbot certonly
      • --dns-digitalocean
      • --dns-digitalocean-credentials ~/certbot-creds.ini
      • -d '*'

      Note that you cannot use the --nginx or --apache plugins to automatically configure those servers with a wildcard certificate. We use the certonly command instead, to only download the certificate.

      When running the above command, you may be presented with a few questions to answer if this is your first time running Certbot. After answering them, Cerbot will perform the challenge, the Let’s Encrypt servers will verify it, and your new certificate will be downloaded and saved to /etc/letsencrypt/. You should see output similar to the following:


      IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/ Your key file has been saved at: /etc/letsencrypt/live/ Your cert will expire on 2021-09-27. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: Donating to EFF:

      You have successfully generated a wildcard SSL certificate! Your next step is to configure your server application to use it. We’ll link to some resources that can help with this in the next section.


      In this tutorial you configured Certbot and downloaded a wildcard SSL certificate from the Let’s Encrypt certificate authority. You are now ready to configure your server software to use this certificate to secure its connections.

      For more information on what certificate files were downloaded, and how to handle gracefully restarting your applications when Certbot automatically updates your certificates, take a look at Steps 3 and 4 of our tutorial How To Use Certbot Standalone Mode to Retrieve Let’s Encrypt SSL Certificates on Ubuntu 18.04.

      Source link

      How to Retrieve Let’s Encrypt SSL Wildcard Certificates using CloudFlare Validation on CentOS 7

      The author selected to receive a donation as part of the Write for DOnations program.


      Let’s Encrypt is a certificate authority (CA) that provides free certificates for Transport Layer Security (TLS) encryption. It provides a software client called Certbot which simplifies the process of certificate creation, validation, signing, installation, and renewal.

      Let’s Encrypt now supports wildcard certificates which allow you to secure all subdomains of a domain with a single certificate. This will be useful if you want to host multiple services, such as web interfaces, APIs, and other sites using a single server.

      To obtain a wildcard certificate from Let’s Encrypt you have to use one of Certbot’s DNS plugins, which include:

      • certbot-dns-cloudflare
      • certbot-dns-route53
      • certbot-dns-google
      • certbot-dns-digitalocean

      The plugin you choose depends on which service hosts your DNS records. In this tutorial you will obtain a wildcard certificate for your domain using CloudFlare validation with Certbot on CentOS 7. You’ll then configure the certificate to renew it when it expires.


      To complete this tutorial, you’ll need the following:

      Step 1 — Installing Certbot

      The certbot package is not available through CentOS’s package manager by default. You will need to enable the EPEL repository to install Certbot and its plugins.

      To add the CentOS 7 EPEL repository, run the following command:

      • sudo yum install -y epel-release

      Once the installation completes, you can install certbot:

      • sudo yum install -y certbot

      And then install the CloudFlare plugin for Certbot:

      • sudo yum install -y python2-cloudflare python2-certbot-dns-cloudflare

      If you are using another DNS service, you can find the corresponding plugin using the yum search command:

      • yum search python2-certbot-dns

      You’ve prepared your server to obtain certificates. Now you need to get the API key from CloudFlare.

      Step 2 — Getting the CloudFlare API

      In order for Certbot to automatically renew wildcard certificates, you need to provide it with your CloudFlare login and API key.

      Log in to your Cloudflare account and navigate to the Profile page.

      Click the View button in the Global API Key line.

      CloudFlare Profile - API Keys

      For security reasons, you will be asked to re-enter your Cloudflare account password. Enter it and validate the CAPTCHA. Then click the View button again. You’ll see your API key:

      CloudFlare Profile - API Keys

      Copy this key. You will use it in the next step.

      Now return to your server to continue the process of obtaining the certificate.

      Step 3 — Configuring Certbot

      You have all of the necessary information to tell Certbot how to use Cloudflare, but let’s write it to a configuration file so that Сertbot can use it automatically.

      First run the certbot command without any parameters to create the initial configuration file:

      Next create a configuration file in the /etc/letsencrypt directory which will contain your CloudFlare email and API key:

      • sudo vi /etc/letsencrypt/cloudflareapi.cfg

      Add the following into it, replacing the placeholders with your Cloudflare login and API key:


      dns_cloudflare_email = your_cloudflare_login
      dns_cloudflare_api_key = your_cloudflare_api_key

      Save the file and exit the editor.
      With Cloudflare's API key, you can do the same things from the command line that you can do from the Cloudflare UI, so in order to protect your account, make the configuration file readable only by its owner so nobody else can obtain your key:

      • sudo chmod 600 /etc/letsencrypt/cloudflareapi.cfg

      With the configuration files in place, let's obtain a certificate.

      Step 4 — Obtaining the Certificate

      To obtain a certificate, we'll use the certbot command and specify the plugin we want, the credentials file we want to use, and the server we should use to handle the request. By default, Certbot uses Let’s Encrypt’s production servers, which use ACME API version 1, but Certbot uses another protocol for obtaining wildcard certificates, so you need to provide an ACME v2 endpoint.

      Run the following command to obtain the wildcard certificate for your domain:

      • sudo certbot certonly --cert-name your_domain --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflareapi.cfg --server -d "*.your_domain" -d your_domain

      You will be asked to specify the email address that should receive urgent renewal and security notices:


      ... Plugins selected: Authenticator dns-cloudflare, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): your email

      Then you'll be asked to agree to the Terms of Service:


      ------------------------------------------------------------------------------- Please read the Terms of Service at You must agree in order to register with the ACME server at ------------------------------------------------------------------------------- (A)gree/(C)ancel: A

      Then you'll be asked to share your email address with the Electronic Frontier


      ------------------------------------------------------------------------------- Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: N

      Then Certbot will obtain your certificates. You will see the following message:


      IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your_domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your_domain/privkey.pem Your cert will expire on 2018-07-31. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: Donating to EFF:

      Now you have your wildcard certificate. Let's take a look at what Certbot has downloaded for you. Use the ls command to see the contents of the directory that holds your keys and certificates:

      • sudo ls /etc/letsencrypt/live/your_domain


      cert.pem chain.pem fullchain.pem privkey.pem README

      The README file contains information about these files:

      $ cat /etc/letsencrypt/live/your_domain/README

      You'll see output like this:


      This directory contains your keys and certificates.
      `privkey.pem`  : the private key for your certificate.
      `fullchain.pem`: the certificate file used in most server software.
      `chain.pem`    : used for OCSP stapling in Nginx >=1.3.7.
      `cert.pem`     : will break many server configurations, and should not be used
                       without reading further documentation (see link below).
      We recommend not moving these files. For more information, see the Certbot
      User Guide at

      From here, you can configure your servers with the wildcard certificate. You'll usually only need two of these files: fullchain.pem and privkey.pem.

      For example, you can configure several web-based services:


      To do this, you will need a web server, such as Apache or Nginx. The installation and configuration of these servers is beyond the scope of this tutorial, but the following guides will walk you through all the necessary steps to configure the servers and apply your certificates.

      For Nginx, take a look at these tutorials:

      For Apache, consult these tutorials:

      Now let's look at renewing the certificates automatically.

      Step 5 — Renewing certificates

      Let’s Encrypt issues short-lived certificates which are valid for 90 days. We'll need to set up a cron task to check for expiring certificates and renew them automatically.

      Let's create a cron task
      which will run the renewal check daily.

      Use the following command to open the crontab file for editing:

      Add the following line to the file to attempt to renew the certificates daily:


      30 2 * * * certbot renew --noninteractive
      • 30 2 * * * means "run the following command at 2:30 am, every day".
      • The certbot renew command will check all certificates installed on the system and update any that are set to expire in less than thirty days.
      • --noninteractive tells Certbot not to wait for user input.

      You will need to reload your web server after updating your certificates. The renew command includes hooks for running commands or scripts before or after a certificate is renewed. You can also configure these hooks in the renewal configuration file for your domain.

      For example, to reload your Nginx server, open the renewal configuration file:

      • sudo vi /etc/letsencrypt/renewal/your_domain.conf

      Then add the following line under the [renewalparams] section:


      renew_hook = systemctl reload nginx

      Now Certbot will automatically restart your web server after installing the updated certificate.


      In this tutorial you've installed the Certbot client, obtained your wildcard certificate using DNS validation and enabled automatic renewals. This will allow you to use a single certificate with multiple subdomains of your domain and secure your web services.

      Source link