SSL Certificate Renewal Automation
SSL Certificate Renewal Automation
#!/bin/bash
# --------------------------------------------------------------------
# Script Name: ssh_certificate_lets_encrypt.sh
# Author: Shiivam Agnihotri
# Date: (12 March 2024)
# Description: Validate and Renew SSL certificate using Let’s Encrypt.
# --------------------------------------------------------------------
Explanation
#!/bin/bash: This line is called a shebang and indicates that the script should be
executed using the Bash shell.
Comments: Lines starting with # are comments and are ignored by the shell. They are
used to provide information about the script, such as its purpose, author, and date.
The script begins by defining variables for the domain name (DOMAIN) for which the SSL
certificate is issued and the email address (EMAIL) associated with the certificate.
The script specifies the path to the Let's Encrypt script (certbot). This script is
responsible for certificate management, including renewal.
Certificate Path:
The path to the SSL certificate (CERTIFICATE_PATH) is defined. This certificate path is
typically where Let's Encrypt stores the certificate files.
A path to a log file (LOG_FILE) is specified. This log file will contain information about
the certificate renewal process.
The script uses the --dry-run option with certbot to check if the certificate needs
renewal. This option performs a test renewal without actually updating the certificate.
If the dry-run indicates that renewal is needed, the script executes the certificate
renewal process non-interactively (--noninteractive), agreeing to the Let's Encrypt terms
of service (--agree-tos) and providing the email address for notifications (--email).
If the renewal process is successful, the script logs the event and restarts the web
server to apply the changes.
Logging:
Throughout the script, various actions and outcomes are logged to the log file specified
earlier. This helps in tracking the certificate renewal process and troubleshooting any
issues
If you want to execute this script on every Sunday at 6pm then you can update like this
in crontab:
0 18 * * 0 /path/to/your/script.sh
Explanation:
If you are looking for a Dedicated 1:1 session with me to boost your DevOps
Productivity, then please book a session from here: https://topmate.io/shivam_agnihotri