Read list of domains from text file and create SSL cert for them

Hello everyone,

this a question for bash gurus. I want to create a certificate using the webroot plugin. Basically, what I’d like to do is

certbot certonly --webroot -w /var/www/ -d domain1 -d domain2 -d domain3

However, I don’t want to type in every single domain. I already have a file which contains a list of all the domains (approx. 50 domains, one domain per line):


I’m looking for a bash command that reads the list of domains from the file and passes them to certbot so that I don’t have to manually type or copy&paste them one by one.

Thanks in advance,

You could do something like this:

certbot certonly --webroot -w /var/www/ $(sed 's/^/-d /' domains.txt)

Of course that only works if all your domains use the same webroot.


Thank you very much. I'll try this out within the next couple of days.

They do. They're all on the same virtual host.

@jmorahan’s solution is excellent!

If you do this, please bear in mind that there is a Let’s Encrypt limit of 100 domains in a single cert, so if you someday acquire more and more domains, there is a limit to the applicability of this or any technique. But you could then split the list into two and just run two commands like @jmorahan’s to acquire two separate certificates. :slight_smile:

1 Like

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