Lightsail : how to auto-renew SSL certificate ?

Referring to this piece of documentation: https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress

I do not need a Load Balancer, and thus don’t want to pay for one.

How do I get the SSL certificate to automatically renew itself ? I do not want to have to SSH every 2 months to repeat all these steps…

`certbot renew` apparently does the trick. But when I run it, it says that the certificate isn’t yet set to expire. This leads me to think that it’s a simple command that I’ll have to run every 2 months, rather than a command which takes care of running the appropriate set of commands automatically every 2 months.

How do I get this process automatized ?

A cron script that runs once a month can do the renewal automatically.

The Bitnami Lightsail WP renew instructions are here in Step 5: Renew The Let’s Encrypt Certificate.https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/

It tries to renew once a month, shown by "0 0 1 * * " in the crontab file.

https://crontab.guru/ is really helpful if you want to change that.

I generally write the crontab to a log file as well. I can post a sample if that would help.

Edit: or maybe just use the “Bitnami HTTPS Configuration Tool” if you’re able to! I haven’t tried it yet.

Based off your link I am assuming you are using the Lightsail “WordPress” instance. Which is running Bitnami. Refer to bitnami documentation https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/ bottom of the page has the guide to auto renew with cron job as above.

While you are there bitnami has great documentation and will pretty much have the answer to all of these type of questions.

https://www.multicastbits.com/guide-secure-unifi-cloud-controller-on-aws-lightsail-signed-with-lets-encrypt-ssl/#Set_up_Cronjob_for_SSL_auto_Renewal

Looks pretty solid. Thanks!

I’ve a feeling that using the cron job to run `certbot new` might be the same as using it to run the 3 lines of code they are proposing?

Yeah pretty much. Just this is using their own script.

Wonderful. Thank you so much for your help!

So, I’ve set up a cron through `crontab -e`, and selection “nano” as the editor.

Entered

0 0 1 * * /opt/bitnami/letsencrypt/scripts/renew-certificate.sh 2> /dev/null

at the end of the file, saved (Ctrl+O), and exited (Ctrl+X).

I was prompted to choose the destination of the crontab, and I pressed enter for the default value, which pointed to a “tmp” folder. This is what made me think I hadn’t done it properly.

Typing `contrab -l` from within where I created “renew-certificate”, says there are no crontab.

Not sure that its location matters (it varies by OS, but is often at /var/spool/cron/crontabs/root).

What happens when you type “sudo crontab -e”? Can you see the cron job? It will display a path at the top like it’s in a tmp file, but that’s not something you need to remember - it’s accessed by the “crontab -e” command, not the path.

To see if it’s working, add a log file, and change the cron runtime to something soon, like

0 22 * 4 * /opt/bitnami/letsencrypt/scripts/renew-certificate.sh > /opt/bitnami/letsencrypt/logs/lego.log 2>&1

(0 22 * 4 * = 11pm every day in April)

if /opt/bitnami/letsencrypt/logs doesn’t exist, you’ll need to add it:

sudo mkdir /opt/bitnami/letsencrypt/logs

After 11, check if there’s a log file, and if the script ran:

cat /opt/bitnami/letsencrypt/logs/lego.log

or maybe

sudo cat /opt/bitnami/letsencrypt/logs/lego.log

Hey there, while we’re here: do you happen to know how I can bootstrap the LightSail instance (post-creation!) with the setup of the crontab?

I remember seeing bootstrapping options when initially setting up the instance, but now I can’t see where to edit that.

Finally got around to doing it. Thanks for your help! The suggested default location was indeed fine.