Install Certbot on Debian with Cloudflare DNS
This guide will help you install Certbot on a Debian system and configure it to use the Cloudflare DNS plugin to manage SSL certificates.
Step 1: sudo apt install snapd
First, update your package list and install snapd:
1 2 |
|
Once snapd is installed, exit the ssh terminal and re-login to ensure snap’s paths are updated properly.
Step 2: Update snapd
1 |
|
Step 3: Remove certbot-auto and any Certbot OS packages
If you have previously installed Certbot via other methods, such as using apt, you'll need to remove those versions to avoid conflicts:
1 |
|
Step 4: Install certbot
Now, install Certbot via the snap package:
1 |
|
To ensure the certbot command is available globally, create a symbolic link to the snap binary:
1 |
|
Run this command on the command line on the machine to acknowledge that the installed plugin will have the same classic containment as the Certbot snap.
1 |
|
Step 5: Install Cloudflare DNS plugin
To manage DNS challenges with Cloudflare, install the Cloudflare DNS plugin:
1 |
|
Step 6: Set up credentials
Go to the Cloudflare dashboard and create a new API token. The Token needed by Certbot requires Zone:DNS:Edit
permissions for only the zones you need certificates for. Copy the new API token value and save it in a file at ~/.secrets/certbot/cloudflare.ini
1 2 |
|
Make sure the file has restricted permissions
1 |
|
Step 7: Request SSL Certificates
You can now use Certbot to request certificates for your domains using the Cloudflare DNS plugin.
For a single domain (e.g., example.com):
1 2 3 4 |
|
For multiple domains (e.g., example.com and www.example.com):
1 2 3 4 5 |
|
For a wildcard certificate (e.g., *.example.com):
1 2 3 4 |
|
If you're using Apache and want Certbot to automatically configure SSL for your sites, add the -i apache
flag:
1 2 3 4 5 |
|
After obtaining the SSL certificate, you need to configure Apache to serve your site over HTTPS. Ignore this step if you run certbot with -i apache
option.
- Redirect HTTP to HTTPS: Add the following rewrite rules to the
block in your Apache configuration file (e.g., /etc/apache2/sites-available/example.com.conf):
1 2 3 4 5 6 7 8 9 |
|
- Enable SSL: In the
block, specify the paths to your SSL certificates:
1 2 3 4 5 6 7 8 |
|
Step 8: Test automatic renewal
Certbot certificates are valid for 90 days, but you can set up automatic renewal. First, test if automatic renewal works by running a dry run:
1 |
|
To check the status of the renewal timer, use the following command:
1 |
|