SSL certificates are an essential part of the internet, ensuring that data is securely transmitted between client and host. In this guide, we show you how to set up the open-source tool Certbot to request free SSL certificates from the nonprofit certificate authority Let's Encrypt.
To use Certbot, you need a Linux server and a domain you own. You must have access to the domain's DNS settings and must create an A DNS record for each root domain or subdomain you want to use, pointing to the IP address of your Linux server.
Certbot also offers additional plugins that let you set up certificates for domains with just one click—compatible with various web servers like Nginx or Apache. We recommend Nginx, as it is a high-performance and popular open-source web server. Help with setup can be found in our Linux Reverse Proxy guide.
Start by installing the open-source package Certbot, which allows you to request free SSL certificates from Let's Encrypt.
sudo apt install certbot
Once Certbot is installed, you can request certificates for your domain(s). Let's Encrypt and Certbot offer different ACME challenges to verify domain ownership.
We strongly recommend the standard HTTP-01 method, as it enables automatic renewals. If you encounter issues, you can alternatively use the DNS-01 method, which is manual and does not support automatic renewal because it relies on verification via a TXT DNS record.
Use Web Server Plugins If you use a web server like Nginx, Apache, or your own web server, we recommend jumping directly to the Web Server Plugins section below. There, we show how to use additional Certbot plugins for these web servers to perform a “one-click” installation and request certificates without stopping the web server.
With Certbot installed, you can now request certificates for your domain(s). In this example, we use standalone mode, where Certbot starts a temporary web server to perform the necessary actions. This means you must open port 80 in your firewall, and no other web servers or services may be running on port 80 so that the temporary web server can start and the challenge can be retrieved (hence the name HTTP in the challenge).
Use the --standalone parameter in the following command to tell Certbot to use the temporary web server.
# For root domains
certbot certonly --standalone -d [your_root_domain] -d www.[your_root_domain]
# For subdomains
certbot certonly --standalone -d [your_domain]
# Interactive setup
certbot certonly --standalone
After running the command, you may be guided through an initial interactive setup where you enter an email address for certificate communication, followed by an optional mailing list and acceptance of the terms of service.
Certbot now generates an ACME challenge and hosts it via the temporary web server. The Let's Encrypt servers then try to retrieve this from your server. If successful, the certificates are created and saved under /etc/letsencrypt/live/[your_domain].
You can now use the SSL certificates wherever you need them by simply specifying the local path to the certificates.
If you have trouble verifying your domain using the HTTP-01 method, you can alternatively use the DNS-01 method, where you must create a TXT DNS record with a value provided by Let's Encrypt.
As mentioned, this method does not support automatic renewal, unless you set up your own infrastructure for it. Therefore, we recommend using the HTTP-01 method whenever possible.
Use the --preferred-challenges parameter in the following command to tell Certbot you want to use the DNS-01 method.
# For root domains
certbot certonly --preferred-challenges dns-01 -d [your_root_domain] -d www.[your_root_domain] --manual -m [your_email]
# For subdomains
certbot certonly --preferred-challenges dns-01 -d [your_domain] --manual -m [your_email]
# Interactive setup
certbot certonly --preferred-challenges dns-01
After running the command, you may be guided through an initial interactive setup where you enter an email address for certificate communication, followed by an optional mailing list and acceptance of the terms of service.
Certbot will then give you instructions on how to create a TXT DNS record with a specific value. The target hostname is typically _acme-challenge. followed by your domain (in this example, _acme-challenge.zapdocs.example.com). You will find the value in the console.
After creating the record, press Enter to continue. If everything is correct and the record has propagated, the certificates will be created and saved under /etc/letsencrypt/live/[your_domain].
Please be patient, as DNS changes sometimes take a little time to propagate. Usually, this takes only a few minutes, but in rare cases, it can take longer.
You can now use the SSL certificates wherever you need them by simply specifying the local path to the certificates.
Certbot offers various additional web server plugins that make certificate management even easier, as the plugins automatically adjust the relevant server blocks. To use a plugin, simply add the appropriate parameter to your certbot command.
Both methods use the HTTP-01 challenge and work basically the same way. When a plugin is used, Certbot first looks for the server block containing the requested domain as server_name. Then Certbot generates an ACME challenge and temporarily adds a location /.well-known/acme-challenge/... block to the server block configuration.
The Let's Encrypt servers then try to retrieve the challenge from your server. If successful, your certificate is generated and the web server’s server block configuration is automatically adjusted to use HTTPS (port 443) and include paths to the new certificates.
Before using the plugin, make sure it is installed.
sudo apt install python3-certbot-nginx
To use the Nginx plugin, use the --nginx parameter in your command as follows.
# For root domains
certbot --nginx -d [your_root_domain] -d www.[your_root_domain]
# For subdomains
certbot --nginx -d [your_domain]
# Interactive setup
certbot --nginx
If you want to disable automatic “one-click” server block adjustments by Certbot, you can add the certonly parameter, e.g., certbot certonly.
Before using the plugin, make sure it is installed.
sudo apt install python3-certbot-apache
To use the Apache plugin, use the --apache parameter in your command as follows.
# For root domains
certbot --apache -d [your_root_domain] -d www.[your_root_domain]
# For subdomains
certbot --apache -d [your_domain]
# Interactive setup
certbot --apache
If you want to disable automatic “one-click” server block adjustments by Certbot, you can add the certonly parameter, e.g., certbot certonly.
If you run your own local web server that does not use traditional web server software, you might want to use the webroot method to keep your web server running without stopping it.
To use the webroot plugin, use the --webroot parameter in your command. Additionally, you must specify the path to your web server root directory with -w [your_webserver_path] (short for --webroot-path).
# For root domains
certbot --webroot -w [your_webserver_path] -d [your_root_domain] -d www.[your_root_domain]
# For subdomains
certbot --webroot -w [your_webserver_path] -d [your_domain]
# Interactive setup
certbot --webroot -w [your_webserver_path]
A common webroot path is /var/www/html. You can also use this method for web servers like Nginx or Apache if you want to keep the web server running without automatic server block adjustments like with the native plugins.
In most cases, Certbot sets up automatic certificate renewal for you—either via a cron job or a systemd timer. You can test this with the following command, which simulates renewal in dry-run mode:
certbot renew --dry-run
As mentioned, the DNS-01 method does not support automatic renewal via Certbot unless you set up your own infrastructure. Therefore, we recommend using the HTTP-01 method whenever possible.
If everything works as expected, the test should succeed. To check or adjust automatic renewal, find the relevant cron job or timer in /etc/crontab/, /etc/cron.*/*, or via systemctl list-timers.
If automatic renewal is not set up, you can create it yourself via a cron job. Open the crontab with crontab -e. If this is your first time, you will be asked to select an editor—choose the first option /bin/nano.
In the opened Nano editor, add the following line to run renewal daily at 6 a.m. local time:
0 6 * * * certbot renew
Save the file and exit Nano with CTRL + X, confirm with Y, and press ENTER.