This Bash script automates the process of generating SSL certificates for domains using the Certbot tool with Cloudflare DNS validation.
The script does the following:
- Installs required packages.
- Verifies Certbot compatibility (version 2.3 or higher is required).
- Loads the Cloudflare API token from a configuration file.
- Collects domain names from the user.
- Validates that the domains share the same root domain.
- Writes the Cloudflare API token to a file for Certbot.
- Uses the Cloudflare DNS API to generate SSL certificates via Certbot.
- Certbot: The script uses Certbot for SSL certificate generation.
- Cloudflare API Token: You need a Cloudflare API token to perform DNS validation for SSL certificate issuance.
Ensure you have a Cloudflare API token with the Zone.DNS permission. You can create a Cloudflare API token from here.
git clone https://github.com/Narwal25/ssl-cloudflare.git
cd ssl-cloudflareYou need to create a file dns_token_file.sh in the same directory as the script, containing your Cloudflare API token in the following format:
export <your_root_domain>="dns_cloudflare_api_token = <your_cloudflare_api_token>"For example, if your root domain is example.com and your Cloudflare API token is abcdef123456, the file should look like:
export example_com="dns_cloudflare_api_token = abcdef123456"Here's an updated version of the usage instructions that include a non-interactive method to pass domains as arguments to the ./generate_ssl_cloudflare.sh script:
Once the setup is done, simply run the script to generate the SSL certificate.
./generate_ssl_cloudflare.shThe script will prompt you to enter the domains for which you want to generate an SSL certificate.
You can also pass the domain names as arguments to the script, like this:
./generate_ssl_cloudflare.sh example.com www.example.com blog.example.comIn this case, the script will use the provided domains directly without prompting you.
The script will prompt you to enter the domains for which you want to generate an SSL certificate. Enter the domains separated by spaces.
Example input:
example.com www.example.com blog.example.com
If using the non-interactive method, simply pass the domains as arguments when running the script (see above).
The script will check that all domains share the same root domain. If the root domains are different, it will exit with an error.
The script will use your Cloudflare API token to generate the SSL certificate via Certbot. This will involve DNS validation using Cloudflare's DNS API.
Once the SSL certificate generation is successful, the script will output a success message.
- If the script reports that Certbot is incompatible with your version, you need to upgrade Certbot to at least version 2.3.
- If the Cloudflare API token is not found or the token file is missing, make sure you have correctly created
dns_token_file.shand followed the proper format.
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.