This is an OLD post and should only really be used these days for non-standard installations. Instead you should use an addon that automatically keeps your certs up to date, or use the ssl sensor that is integrated into homeassistant
If, like me, you’ve followed the guides and installed a Letsencrypt SSL certificate, it is only valid for 90 days.
This code will allow you to represent the number of days remaining on the certificate as a sensor reading, so when you have only a week or so left you can renew it. You could use the sensor to trigger an alarm, or maybe even an auto-renew command, I haven’t got that far yet myself, but thought I’d share anyway…
Prerequisite - You will need to install ssl-cert-check if it is not already present on your system:
This is a pretty neat idea, but for some reason my returns the following “7 20”
That’s the numeral seven followed by a blank space, then twenty.
Running another command, I get this result on the date: notAfter=Mar 29 03:13:00 2017 GMT
So I am about 20 days away, so the second part of the results would be right, just don’t know where the 7 and blank space comes from and if there is a way to exclude it from the results of this command
Have a play with the number at the end of tail, I guess yours should be “… | tail -c 38”
When ssl-cert-check returns the result in a terminal it draws a pretty (but pointless!) table, so to get the number you want you have to cut off x amount of characters of faff that it produced. For whatever reason yours is one character longer (or shorter? I’m too tired to work it out now ) than mine, but yes, for anybody else who is not getting the correct number in the output, change the cut value in tail.
@berniebl - in fact, can you tell me how many characters are in your first bit of your duckdns url please?
I think that’s what’s afecting the tail number. Mine is 13 characters (dot) duckdns.org . If your is 12 or 14, then I can work out a table for what people’s tail -c number should be. Please let me know
I didn’t realise that it put the url in the same line when I came up with the idea.
The 7 in the previous result was the end of the date for your expiry 03/09/201 7 (or similar), which is the column before in the table.
I guess there must be a way of working out what the number at the end of the command should be to get just the outstanding days, but I’m at a loss at the minute, if more people post their experiences I will try and work it out tomorrow and amend my instructions accordingly
Does the script need to be run from within the certbot folder, or could it run from anywhere with full file path?
I haven’t got that far yet as I’m playing with a million and one other things, but it’s definitely the route I’m heading down. By all means if somebody wants to test these out and post the solutions…
yes. i have updated the command after I done the testing. the certbot-auto path is depend on your system. On mine, it is located in ./certbot/certbot-auto.
anyway, thanks for sharing this. It is the missing link of SSL auto renewal automation I have been planning to do.
but it didn’t appear to do anything. my certificate is only a week old so maybe it won’t renew because of that? Do we need to temporarily port forward like in the initial SSL setup?
I think it doesn’t update unless there’s less than 30 days left on the certificate or something anyway, but this is the bit I haven’t started playing with yet to get a definitive way of doing it.
Basic steps would be:
SSH in to your pi
find (and navigate in to) your certbot folder, wherever you put it depending on which instructions you followed.
run the command “./certbot-auto renew --quiet --no-self-upgrade --standalone --preferred-challenges http-01” and make sure it’s working, see what the output is, etc
type “pwd” and make a note of the full file path (for example /home/hass/certbot)
make sure the hass user has permission to access the folder and contents (if it is in /home/hass/… , it will)
replace the dot at the start of your command with the output you got from pwd
Of course if the path actually was /home/hass/certbot… , and your user is hass, the /home/hass/ bit is redundant, but hopefully you get the idea. This would seem to concur with @masterkenobi 's findings that his command was
Well, in my case I have to temporarily change the port forwarding 443 ext -> 443 int to renew the certificate as my ISP is blocking port 80. So the auto-renew is not useful but the SSL expiration sensor is.