Debian 13 Tutorial / Verify HTTPS Certificates, Certbot Renewal and Nginx Deployment

To operate HTTPS on Debian 13, you need to check not only the certificate issuance but also the name, trust chain, expiration, and the certificate actually provided by the web server. Once a public domain and external verification path are ready, you can configure issuance and renewal with Certbot, and in a lab VM without such conditions, you can learn the same verification flow with a local test certificate authority (CA). The execution verification in this course uses the latter method, and it is distinguished so as not to confuse it with successful public certificate issuance.

Separate Public Issuance from the Local Test-CA Lab

HTTPS is a method of protecting HTTP communication with TLS (Transport Layer Security). Certificates contain information such as the server's public key and the name to be used, and are signed by a certificate authority (CA). Clients verify whether it chains to a trusted CA, whether the connection name matches the certificate, and whether it is within the validity period.

ACME (Automatic Certificate Management Environment) is a protocol for verifying control over domains and automating certificate issuance and renewal. Certbot is a client that uses this. CAs created locally are not trusted by Internet browsers by default and are not substitutes for public site certificates.

Path Requirements Scope of verification in this course
Public Certbot issuance Controllable real domain, DNS/external access according to the verification method This is a conditional operation procedure that checks official documents and installed options. Actual issuance was not performed.
Local test CA Separate Debian VM with sudo access, Nginx·OpenSSL·curl We directly verified trust and name validation, HTTPS response, certificate reissuance, and reload.

The Let’s Encrypt challenge-type guide explains that HTTP-01 requires external access to a token through the domain on port 80. Opening only VM port 8443 or changing a local hosts file does not satisfy this condition. DNS-01 requires control of the public DNS TXT record; automated renewal needs an appropriate DNS plugin and carefully scoped API permissions.

Inspect Installed Versions and the Actual Renewal Timer

For practice, use the VM from the previous lecture where Nginx is running normally, and make sure port 8443 and the dedicated path below are empty. On servers with existing public sites, safely back up the configuration, certificates, and keys, and define the scope of changes before proceeding.

sudo apt update
sudo apt install nginx openssl curl certbot python3-certbot-nginx
openssl version
certbot --version
sudo nginx -t
ss -ltn
systemctl cat certbot.timer certbot.service
systemctl list-timers certbot.timer --no-pager

The verification VM used OpenSSL 3.5.7, Certbot 4.0.0, and Nginx 1.26.3. In the Debian package, certbot.timer added a random delay to the two daily reference times and was set with Persistent=true. The certbot.service was a oneshot that executes renew. If the installation method differs, the timer name and schedule may also differ, so check the actual settings.

timer active means that the schedule is activated. It does not mean that a certificate exists or that the renewal/deployment was successful. The certbot certificates result on this VM was No certificates found, and the subsequent local OpenSSL certificates are not automatically registered as Certbot-managed targets.

Create the Local CA and Complete HTTPS Test Site

Run the complete block only when every dedicated lab path listed in its guard is absent. Place the CA key and server key in root-only paths, and keep only the public CA certificate readable by the client in a separate public path. Do not add it to the system or browser trust store. Keys are generated without a password but are restricted with 700 directory and 600 file permissions; this method is for short local practice only.

Run administrator privileges explicitly with sudo bash, and execute the internal commands in a single root shell. Make the CA valid for 3 days and the first server certificate valid for 1 day, including lab26.test in the SAN (Subject Alternative Name). This name is used for local testing only.

sudo bash <<'ROOT'
set -euo pipefail
for p in /var/lib/lf-tls26 /etc/nginx/lf-tls26 /etc/nginx/sites-available/lf-tls26 /etc/nginx/sites-enabled/lf-tls26 /usr/local/sbin/lf-tls26-deploy; do
  if test -e "$p" || test -L "$p"; then echo "Existing: $p" >&2; exit 1; fi
done
install -d -m 755 /var/lib/lf-tls26 /var/lib/lf-tls26/public
install -d -m 700 /var/lib/lf-tls26/private /etc/nginx/lf-tls26
umask 077
openssl req -x509 -newkey rsa:2048 -noenc -sha256 -days 3 -subj '/CN=LF Lab 26 Test CA' -addext 'basicConstraints=critical,CA:TRUE' -addext 'keyUsage=critical,keyCertSign,cRLSign' -keyout /var/lib/lf-tls26/private/ca.key -out /var/lib/lf-tls26/public/ca.crt
chmod 644 /var/lib/lf-tls26/public/ca.crt
openssl req -new -newkey rsa:2048 -noenc -subj '/CN=lab26.test' -keyout /etc/nginx/lf-tls26/server.key -out /var/lib/lf-tls26/private/server.csr
cat > /var/lib/lf-tls26/private/leaf.ext <<'EXT'
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=DNS:lab26.test
EXT
openssl x509 -req -in /var/lib/lf-tls26/private/server.csr -CA /var/lib/lf-tls26/public/ca.crt -CAkey /var/lib/lf-tls26/private/ca.key -set_serial 0x26 -days 1 -sha256 -extfile /var/lib/lf-tls26/private/leaf.ext -out /etc/nginx/lf-tls26/server.crt
cat > /etc/nginx/sites-available/lf-tls26 <<'CONF'
server {
    listen 127.0.0.1:8443 ssl;
    server_name lab26.test;
    ssl_certificate /etc/nginx/lf-tls26/server.crt;
    ssl_certificate_key /etc/nginx/lf-tls26/server.key;
    default_type text/plain;
    return 200 "TLS LAB 26\n";
}
CONF
ln -s /etc/nginx/sites-available/lf-tls26 /etc/nginx/sites-enabled/lf-tls26
nginx -t
systemctl reload nginx
sleep 1
ROOT

Among the generated files, ca.key and server.key are private keys, and ca.crt and server.crt are public certificates. Do not assume that setting the Common Name (CN) is enough for name validation; check the SAN as well. The server certificate's extensions specify that it is not a CA and that it is intended for server authentication. The configuration and conditions for accessing private keys are also explained in the Nginx HTTPS setup document .

After checking the configuration and reloading, make requests as a regular user on the Debian VM. If a connection fails immediately after reload, try again after a short while and check ss and service logs. The --resolve option maps names to addresses only for this request without changing DNS, and --cacert makes the test CA trusted only for this request.

curl --noproxy '*' -fsS --cacert /var/lib/lf-tls26/public/ca.crt --resolve lab26.test:8443:127.0.0.1 https://lab26.test:8443/

The expected response is TLS LAB 26. This success is based on verification under conditions of loopback, specified CA, and specified name, and does not reflect results from public DNS or regular browser trust checks.

Distinguish Trust Errors from Name Mismatches

For the first request below, do not specify the test CA, and for the second request, specify the CA but connect to an IP address not included in the certificate. Both commands are expected to fail. Run this comparison in a fresh ordinary shell without set -e enabled, and read the exit code immediately after each request; an errexit shell could exit before echo runs.

curl --noproxy '*' -sS --resolve lab26.test:8443:127.0.0.1 https://lab26.test:8443/
echo "curl exit: $?"
curl --noproxy '*' -sS --cacert /var/lib/lf-tls26/public/ca.crt https://127.0.0.1:8443/
echo "curl exit: $?"

In the verification, both cases returned a curl exit code 60, but the first was caused by an untrusted issuer, and the second by a name mismatch. Don’t just group them together based on the number; read the error message as well. The result that succeeded by turning off verification with -k cannot be used for certificate trust checks.

Check the chain, name, and expiration of the file itself as follows. The server certificate path is inside the root-only directory, so sudo is used.

sudo openssl verify -CAfile /var/lib/lf-tls26/public/ca.crt -verify_hostname lab26.test /etc/nginx/lf-tls26/server.crt
sudo openssl x509 -in /etc/nginx/lf-tls26/server.crt -noout -serial -dates -ext subjectAltName
sudo openssl x509 -in /etc/nginx/lf-tls26/server.crt -noout -checkend 3600

-checkend 3600 checks whether it will expire within the next 3,600 seconds, and returns a non-zero status if expiration is near. This alone does not verify the chain or the name. According to OpenSSL x509 option description, distinguish purposes for date, SAN, and chain checks.

Compare the Certificate File with the Certificate Nginx Serves

Even if you replace the server certificate, you cannot guarantee that the running Nginx will serve the new certificate. First, check the serial number of the certificate provided in a new connection. -servername passes the desired server name through TLS’s SNI (Server Name Indication). This command is for observing the certificate, and actual trust and name verification is performed by the preceding curl and openssl verify.

openssl s_client -connect 127.0.0.1:8443 -servername lab26.test < /dev/null 2>/dev/null | openssl x509 -noout -serial -fingerprint -sha256

Run this replacement comparison once in the fresh lab. Preserve the first server-before.crt rather than overwriting it on repeated attempts. These certificates intentionally expire after only a few days; use a correct system clock and regenerate the dedicated lab when necessary.

The initial serial number is 26 in hexadecimal. Next, using the same test CA and certificate signing request (CSR), create a new certificate with a 2-day validity period and serial number 27, and after verification is complete, replace the file name in the same directory. This comparison is a local reissue where the deployment step is observed separately, not an ACME renewal.

sudo bash <<'ROOT'
set -euo pipefail
umask 077
cp -a /etc/nginx/lf-tls26/server.crt /var/lib/lf-tls26/private/server-before.crt
openssl x509 -req -in /var/lib/lf-tls26/private/server.csr -CA /var/lib/lf-tls26/public/ca.crt -CAkey /var/lib/lf-tls26/private/ca.key -set_serial 0x27 -days 2 -sha256 -extfile /var/lib/lf-tls26/private/leaf.ext -out /etc/nginx/lf-tls26/server.next.crt
openssl verify -CAfile /var/lib/lf-tls26/public/ca.crt -verify_hostname lab26.test /etc/nginx/lf-tls26/server.next.crt
mv /etc/nginx/lf-tls26/server.next.crt /etc/nginx/lf-tls26/server.crt
ROOT

Immediately after completing the above block, the serial number of the file is 27, but the certificate received in a new connection was still 26. This is evidence that file saving success and deployment success are different. The known-good server-before.crt was preserved at this step.

The dedicated deployment script below reloads only upon successful verification. In this practice, it was confirmed during preparation that a file with this name does not yet exist. It is not used to overwrite existing scripts on production servers.

sudo tee /usr/local/sbin/lf-tls26-deploy > /dev/null <<'HOOK'
#!/bin/sh
set -eu
/usr/sbin/nginx -t
/usr/bin/systemctl reload nginx
HOOK
sudo chmod 700 /usr/local/sbin/lf-tls26-deploy
sudo /usr/local/sbin/lf-tls26-deploy
openssl s_client -connect 127.0.0.1:8443 -servername lab26.test < /dev/null 2>/dev/null | openssl x509 -noout -serial -fingerprint -sha256
curl --noproxy '*' -fsS --cacert /var/lib/lf-tls26/public/ca.crt --resolve lab26.test:8443:127.0.0.1 https://lab26.test:8443/

During verification, after reload, the serial number of the new connection changed to 27 and the HTTP response was normal. Immediately, if the old worker is shutting down, check again with a new connection shortly afterward. If the configuration check fails, reload is not performed, and the correspondence of files/keys and the path/permissions are investigated. When restoring this practice certificate, copy the preserved server-before.crt to server.crt and perform verification, reload, and certificate provision check in the same order.

Use Certbot Only After Preparing a Public Domain

This procedure applies only when operating an actual domain. Separate from the local site at 127.0.0.1:8443, the domain’s IPv4 A and any published IPv6 AAAA records must point to the correct server, and HTTP-01 access on port 80 must be available on all used paths. Also, check for incorrect IPv6 addresses, proxy, CDN, firewall, and NAT settings. Verify domain access from other networks and adjust the server_name in the Nginx site to match the actual domain.

A Certbot dry run still contacts the staging service and may temporarily adjust and reload the web server. Back up the relevant site configuration first. If nginx -t or staging validation fails, stop and correct it before attempting production issuance; the following commands are not a batch to run through after an error.

Below is a conditional command applied to an already prepared Nginx site. Enter the domain you control and a contact email, and first back up the settings on the actual server. --dry-run attempts a staging verification, so it does not need to be executed on a VM without external conditions.

read -r -p "Real domain you control: " domain
read -r -p "Certificate contact email: " email
sudo nginx -t
sudo certbot certonly --nginx --dry-run -d "$domain" --email "$email" --agree-tos

Staging certificates are not trusted by general clients. Following Let’s Encrypt staging instructions, resolve validation errors first, and then proceed with production issuance. Even if dry-run succeeds, the production certificate is not saved. Under normal conditions, the following command issues a production certificate and modifies the Nginx configuration, so changes should be reviewed.

sudo certbot --nginx -d "$domain" --email "$email" --agree-tos --redirect
sudo certbot certificates
sudo nginx -t
curl -I "https://$domain/"

Verify the actual certificate name and the live path using the certificates output. Nginx must be linked with fullchain.pem containing the server certificate and required intermediate certificates, along with the corresponding privkey.pem. Do not end the verification by just confirming the files exist; check the external HTTPS response and verify the provided certificate's name, issuer, and expiration.

Operational renewal verification is performed with sudo certbot renew --dry-run. The help for the installed 4.0.0 version indicates that deploy hooks are not executed in the default dry-run and that --run-deploy-hooks must be added. If you have configured your own deploy hooks in addition to the reapplication handled by the Nginx plugin, review the targets and duplicate reload, and tests including hooks should be performed within the maintenance scope.

certbot --help all | less
sudo certbot renew --dry-run
systemctl list-timers certbot.timer --no-pager
sudo journalctl -u certbot.service -n 50 --no-pager

The result of ending without any action because there is nothing to renew is not evidence of a successful renewal. First, check whether there are any certificates actually being managed, and separately record the renewal results, deployment results, and the certificates of new connections at the required times. For the meaning of plugins and hooks, refer to Certbot Official Usage Guide , but prioritize checking the help of the installed version and the actual configuration.

Remove Only the Local TLS Lab

Readers who have configured the public Certbot settings must not apply this cleanup section to public sites. The block below removes the link for lf-tls26 created earlier, then checks and reloads, and only deletes the dedicated key, certificate, and folder if the 8443 listener has disappeared. Since the trust store has not been changed, there is no need to remove the system CA either.

sudo bash <<'ROOT'
set -euo pipefail
rm -- /etc/nginx/sites-enabled/lf-tls26
nginx -t
systemctl reload nginx
sleep 1
if ss -ltnH | grep -q '127.0.0.1:8443'; then echo 'TLS listener remains' >&2; exit 1; fi
rm -- /etc/nginx/sites-available/lf-tls26 /usr/local/sbin/lf-tls26-deploy /etc/nginx/lf-tls26/server.crt /etc/nginx/lf-tls26/server.key
rm -- /var/lib/lf-tls26/private/ca.key /var/lib/lf-tls26/private/server.csr /var/lib/lf-tls26/private/leaf.ext /var/lib/lf-tls26/private/server-before.crt /var/lib/lf-tls26/public/ca.crt
rmdir /etc/nginx/lf-tls26 /var/lib/lf-tls26/private /var/lib/lf-tls26/public /var/lib/lf-tls26
ROOT

On the verification VM, dedicated HTTPS sites, keys, CAs, and deployment scripts were removed, and the original Nginx default configuration hash was retained. The Certbot package and active timers remained, but there were no managed certificates. This state is not considered the same as the automatic renewal operation of public certificates.