Sub topic 6
Installing Certbot
Certbot is the ACME client you will use to request and renew Let's Encrypt certificates. This chapter covers installing it on Debian or Ubuntu, confirming the install works, and understanding what the install adds to your system. It stops before requesting a certificate. The next chapters cover staging, rate limits, and issuance.
This chapter assumes you can use a Linux shell with sudo, that nginx is already installed, and that you know the basics of systemd services and timers.
What Certbot does
An ACME client is a program that speaks the ACME protocol to a certificate authority (CA). It creates an account, proves you control a domain, and downloads the signed certificate. Certbot is the client maintained by the Electronic Frontier Foundation. It does four jobs:
- It registers an ACME account with Let's Encrypt and stores the account key.
- It answers domain validation challenges, either by itself or through a plugin.
- It writes the certificate and private key files under
/etc/letsencrypt/. - It renews certificates before they expire, on a schedule.
Certbot is a client only. It is not a daemon that stays running. The scheduled renewal runs it briefly, and it exits.
Choosing an install method
Certbot can be installed in several ways. The right choice depends on how much you value distribution integration versus newest features.
| Method | Strength | Weakness |
|---|---|---|
| Distribution package (`apt`) | Fits normal system updates, uses the system's systemd timer | Version can lag behind the latest release |
| snap | Newest release, upstream's recommended method on many distributions | Needs snapd, and the snap's layout differs from a package install |
| pip in a virtual environment | Full control over the version | You must manage updates and the renewal timer yourself |
This tutorial uses the distribution package. It is the simplest to audit and maintain on a server that already uses apt for everything else. If you use another method, the later commands for issuing and renewing certificates behave the same. Only the way the renewal timer is installed changes.
Installing from the distribution repositories
The package named certbot provides the client. The package named python3-certbot-nginx provides the nginx plugin, which lets Certbot answer HTTP-01 challenges through your running nginx and read its configuration.
sudo apt update
sudo apt install certbot python3-certbot-nginx
certbot --versionapt update refreshes the package lists first, so you install the current version from your repositories instead of an outdated cached one. The last command prints a version number such as certbot 2.9.0. The exact number depends on your distribution release.
If certbot --version prints a version, the client is installed and on your PATH. If you see command not found, the install failed or your shell has cached an old command lookup. Run hash -r and try again.
What the install adds
The package puts several things on your system. Knowing them helps when you troubleshoot later.
- The
certbotcommand, normally at/usr/bin/certbot. - A systemd timer and service for renewal. On Debian and Ubuntu these are
certbot.timerandcertbot.service. - The directory
/etc/letsencrypt/, which will hold your account data, certificates, and renewal settings. - The directory
/var/log/letsencrypt/, where Certbot writes its logs.
Some distributions use a cron entry in /etc/cron.d/certbot instead of, or alongside, the timer. Later chapters on renewal show how to tell which one is active on your server.
Understanding the nginx plugin
Certbot has two kinds of plugins. An authenticator proves domain control. An installer edits your web server configuration to use the certificate. The nginx plugin can do both, but you can ask for only one part.
In this tutorial you will use the certonly subcommand with --nginx. That asks the plugin to authenticate the domain and obtain the certificate, but not to edit your nginx files. You then write the TLS configuration yourself. This keeps your configuration under your control and makes it easy to keep in version control.
The alternative modes are worth knowing by name so you can recognize them in other guides:
--nginxwithoutcertonlyobtains the certificate and also rewrites your nginx server blocks.--webroot -w /var/www/htmlplaces challenge files in a directory your web server already serves. It does not need the nginx plugin.--standalonestarts a temporary web server on port 80. It needs port 80 to be free, so nginx must be stopped first.
Where the pieces fit
The diagram shows what happens when Certbot runs with the nginx plugin. Certbot talks to the CA over HTTPS, and the CA connects back to your server on port 80 to check the challenge.
You do not run this flow yet. It shows why the install includes the plugin and why port 80 matters later.
Checking the installation
After the install, confirm three things before moving on.
First, check that the client and the plugin are both present:
certbot --version
certbot pluginscertbot plugins lists the available authenticators and installers. You should see nginx in the list. If it is missing, python3-certbot-nginx is not installed or does not match the installed certbot version.
Second, check that the directory layout exists:
sudo ls /etc/letsencrypt/On a fresh install you will typically see renewal-hooks and possibly cli.ini. The live, archive, and accounts directories appear only after your first certificate request.
Third, check that renewal is scheduled:
systemctl list-timers | grep -i certbotYou should see a line for certbot.timer with the next time it will run. If the output is empty, your system may use cron or you may have installed by another method. Do not worry yet, since a later chapter covers renewal in detail.
Common installation problems
- Package not found. Run
sudo apt updateand make sure theuniverserepository is enabled on Ubuntu. Some minimal images ship with onlymain. - Plugin version mismatch. Mixing a snap-installed
certbotwith an apt-installed plugin does not work. Use one method for both pieces. If you have both, remove one before continuing. - Old version. Older distribution releases can carry an outdated Certbot. Check the version against the project's current release. If a feature in a guide is missing, use the snap or pip method instead.
- Permissions. Certbot needs root to write under
/etc/letsencrypt/and bind or serve challenges. Running it withoutsudofails with a permission error.
Exercises
Exercise
You installed certbot with apt, but certbot plugins does not list nginx. Name the most likely missing piece and the command that fixes it.
Show answer
The nginx plugin package is missing. Run sudo apt install python3-certbot-nginx, then run certbot plugins again to confirm that nginx appears.
Exercise
Why does this tutorial use certonly --nginx instead of plain --nginx?
Show answer
certonly obtains the certificate but does not edit your nginx configuration. You write the TLS server blocks yourself, so the configuration stays under your control and reviewable.
Exercise
A colleague wants to use --standalone on a server where nginx is running on port 80. What problem will they hit?
Show answer
Standalone mode starts its own temporary web server on port 80, and nginx already holds that port, so Certbot fails to bind it. They must either stop nginx first or use the --nginx or --webroot mode instead.