Script to easily create certificates for hundreds of subdomains (SAN / UCC certificate)

Currently on a single domain, I have hundreds of subdomains, each requiring HTTPS connection.

Needless to say, I hit the 20 certificate/week limit very often :slight_smile:

So I created this simple script below, to assist me in creating SAN / UCC certificates.

Each of these SAN / UCC certificates contain up to 100 SSL certificates.
So, 20 of these can give you SSL certificates for 2000 subdomains

Usage is very simple :

  1. Create a file named domain-list.txt, containing all the subdomains
  2. Execute this script

That’s it

Hope you find it useful.

cheers, HS


#!/bin/bash

# specify the location of Let's Encrypt tool
# with its parameters
certbot='/usr/bin/certbot  --agree-tos --email my@email.com --apache --redirect --expand -n '

vhost=( `cat "domain-list.txt" `)

# loop variables
ssl_exec="${certbot}"
n=1

#################### START ##########################

for t in "${vhost[@]}"
do

	ssl_exec="${ssl_exec} -d $t "
	let "n++"

	# every 100th domain, create a SSL certificate
	if (( n == 100 )); then

		$ssl_exec
		#echo $ssl_exec

	# reset the loop variables
	ssl_exec="${certbot}"
	n=1
fi

done

# create SSl certificate for the rest of the domains
#echo $ssl_exec
$ssl_exec
1 Like

Thanks for sharing your script. Another thing to note for this case is the split command, which splits a file into pieces each containing at most a specified number of lines. For example, split -l 100 will make new files containing 100 lines each of its input file (with the last output file potentially containing fewer than 100 lines).

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.