Technology
Photo of author

How to Delete Certbot Certificate by Domain Name (Let’s Encrypt)

First, list your certificates by running this command :

$ sudo certbot certificates
This command will show you all your certificates and their names

Here’s an immediate way to delete a Certbot certificate by including the domain name in the command like this:

$ sudo certbot delete --cert-name example.com

To avoid problems, you should also delete the Apache configuration associated with this certificate, here’s an exemple for exemple.conf :

$ sudo rm /etc/apache2/sites-available/exemple-le-ssl.conf

This could be useful if the domain name does not appear in the index.

If you need to generate a new certificate, here’s the command :

$ sudo certbot --apache -d exemple.com

If the command dosen’t work, make sure the site is enabled, verify /etc/apache2/sites-available to find the config name:

$ sudo a2ensite exemple.conf 
$ sudo systemctl reload apache2

If you run into some problems, you can type “systemctl status apache2”, this should give you information about the problem.

Here’s an exemple of a virtual host configuration /etc/apache2/sites-available/maximef.conf :

<VirtualHost *:80>
   ServerName maximef.com
   ServerAlias www.maximef.com
   ServerAdmin [email protected]
   DocumentRoot /var/www/wordpress
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.maximef.com [OR]
RewriteCond %{SERVER_NAME} =maximef.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Here’s an exemple of the SSL virtual host configuration /etc/apache2/sites-available/maximef-le-ssl.conf :

<IfModule mod_ssl.c>
<VirtualHost *:443>
   ServerName maximef.com
   ServerAlias www.maximef.com
   ServerAdmin [email protected]
   DocumentRoot /var/www/wordpress
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/maximef.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/maximef.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

1 thought on “How to Delete Certbot Certificate by Domain Name (Let’s Encrypt)”

Leave a Comment