Problem with Certificate Auto Renew

I was going to suggest

grep -r SSLCertificate /etc/apache2

to see how the certificates are or are not referred to within your Apache configuration.

There’s a delete subcommand in Certbot to delete a specific certificate that you no longer need.

I have done the grep command you suggest and I get this output:

Please correct me if I am wrong but, I should delete this 2 pem files bellow:
/etc/letsencrypt/live/mysite.com/fullchain.pem
/etc/letsencrypt/live/mysite.com/privkey.pem

If so, can you tell me what is the correct command on certbot to delete them if not then let me know what I should do.

Thanks!

Nope, there are two problems with this:

  • It will confuse Certbot, because Certbot will still expect to be able to renew this certificate based on the existence of /etc/letsencrypt/renewal/mysite.com.conf.
  • It will break Apache, because your Apache configuration in default-ssl.conf refers to these files! If you try to start Apache while referring to a file that doesn't exist, Apache will fail to start.

I would suggest changing mysite.com in these paths in default-ssl.conf to mysite.com-0001. Then you can use certbot-auto delete --cert-name mysite.com to remove the old certificate.

So, basically I renew that certificate with a different domain, that is what you mean?

Thanks!

No, I’m suggesting that you edit your Apache configuration to stop referring to the mysite.com certificate. Your mysite.com-0001 certificate is apparently already OK. But if you delete the mysite.com certificate without first editing the Apache configuration, then the Apache configuration will be broken, because it currently references this certificate (even though it doesn’t need it for domain name coverage).

Hello @schoen

I think I got what you mean, please feel free to correct me if I am wrong:

I need to edit this file from apache2 => /etc/apache2/sites-available/default-ssl.conf

correct?

I have did a cat on this file for you to see output which is here bellow:

So, I am guessing I should edit this 2 lines:

and change them to the following:

Also I wanted to ask you about last line on this file

This are old subdomains I add on the first time I run certificate, can you tell me if I can delte this since I am not using any of those subdomains anymore just using www.mydomain.com and mydomain.com

If I am wrong please let me know, I am just following this logic since on first config file of apache that I showed you before there is nothing about ssl that is why I am guessing this is the right one.

Thanks again

Yes, that's right.

I don't know the effect of deleting these offhand because I don't know whether a ServerName directive is required in this file.

Hello @schoen

ok I have edited files and even renew certificate and it worked I got this output:

[quote]Saving debug log to /var/log/letsencrypt/letsencrypt.log


Processing /etc/letsencrypt/renewal/mydomain.com-0001.conf

Renewing an existing certificate
Performing the following challenges:
tls-sni-01 challenge for mydomain.com
tls-sni-01 challenge for www.mydomain.com
Waiting for verification…
Cleaning up challenges


new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mydomain.com-0001/fullchain.pem


Processing /etc/letsencrypt/renewal/mydomain.com.conf

Renewing an existing certificate
Performing the following challenges:
tls-sni-01 challenge for www.mydomain.com
Waiting for verification…
Cleaning up challenges


new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/mydomain.com/fullchain.pem

Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/mydomain.com-0001/fullchain.pem (success)
[/quote]

Now to remove other certificate how do I do this? and about previous post the one that matters is the one called server name right? alieses dont matter that much?

Thanks!

If you no longer have any references to /etc/letsencrypt/live/mysite.com/fullchain.pem and its associated files in your Apache configuration, then you can use the command I mentioned in

to delete the mysite.com certificate.

Hello @schoen

Ok, I think I did it right, let me show you the steps I took so you can confirm me if I did it correctly:

Everything works correctly so, far!

So, what I am missing to do? Now I need to change renewal date on contrab, right?

Can you show me how to do it so it renews every 1st of every month? so, it does it once a month or can you tell me why you recommend doing this once a day?

Thanks again @schoen I been learning a lot with you.

The certbot renew command looks at every certificate and tries to renew only those that are less than 30 days away from expiring. This is designed in part for people who might have many different certificates on their servers, which may have been issued at different times.

Trying to renew when necessary is the idea here. Here are some reasons why we prefer this approach (attempt to renew once or twice per day, but only those certificates that are less than 30 days from expiring) to others:

compared to trying to renew on a specific day of the month: if the renewal fails for some reason, you won't try again for a full month (!); also, for people who have several different certificates from us, this will create more risk of running into rate limits

compared to trying to renew immediately before expiration: if the renewal fails for some reason, you won't have very much time to investigate the problem before the certificate expires

compared to trying to renew as soon as permitted (e.g. 1 week after issuance): this seems to create unnecessary load on our servers

If you run certbot renew from cron once or twice per day, you shouldn't have trouble with rate limits because it will check every day, but not actually perform a renewal action most days. But you should get a renewal promptly 30 days before the certificate expires. If this doesn't happen or you get errors or you get a reminder from the Let's Encrypt CA, you then have some time to figure out what the problem is.

The 0 1 1 */2 * time spec in crontab which you mentioned in your very first post renews at 1:00 on the first day of even-numbered months, which is especially risky in terms of what happens if something goes wrong with the renewal for some reason. :slight_smile:

So I would suggest something like

43 3 1 * * cd /usr/local/letsencrypt && ./certbot-auto renew

The renew subcommand is meant to be as convenient and automated as possible for unattended automated renewals. :slight_smile: We have also asked people to choose a random minute for their automated renewals so that we don't get unnecessary load spikes at the beginning of every hour (so that's why I said 43 here).

You can learn more about crontab by reading the manual page (man crontab). The fields are minute, hour, day, month, day of week, command. (Some crontabs come with a comment explaining this!) A * means "every" (e.g. a * for day means "every day").

Awesome information @schoen

Thanks a lot for all so, I had add this line you recommend on crontrab

43 3 1 * * cd /usr/local/letsencrypt && ./certbot-auto renew

Now just 2 questions for me to get clear:

  1. With this command when will renew?

  2. On tutorial he also adds at the end " certonly --apache --renew-by-default --apache -d domain.tld >> /var/log/domain.tld-renew.log 2>&1" should I add that too? His full command is the following:

0 1 1 */2 * cd /usr/local/letsencrypt && ./letsencrypt-auto certonly --apache --renew-by-default --apache -d domain.tld >> /var/log/domain.tld-renew.log 2>&1

Thanks!

I'm sorry, I made a mistake which you exposed by asking this question. I meant to say 43 3 * * * instead of 43 3 1 * *. I wrote the wrong form because I was thinking about your suggestion to renew on the first day of the month.

Maybe you can look at the last paragraph of my previous post to see what the difference between these two is.

I think I explained in

some reasons why this is not desirable and shouldn't be used.

Hello @schoen

No problem, I have change command on contrab to what you recommend the command bellow, please confirm if is correct:

I am sorry if you explained, I am just asking again because I did not understand it completely sorry for my ignorance but, for me this system is all new and I am learning as I go so, can you just tell the 2 questions bellow:

  1. With this command when will certficate would get renew? (So I can check this cronjob works correctly)

  2. Should I do anything else or the setup is all correct now and should not worry anymore?

Thanks again @schoen you been the best and again I am sorry for my ignorance I hope it does not bother you because for me this is all new.

At 3:43 in the morning when it's less than 30 days from expiring.

[quote]2) Should I do anything else or the setup is all correct now and should not worry anymore?
[/quote]

You should wait until the certificate is 30 days from expiring and check that the cron job succeeds in renewing your certificate at the specified time.

Ok perfect, thanks for explaining to me. Can I just ask you one last favor can you give me command for cronjob so it renews every 5 days, so, I dont have to wait so long to check if it renews correctly?

Thanks again @schoen

There is no change to the cron job that would achieve this. Remember that that cron job runs every day, not every month.

If you go to /etc/letsencrypt/renewal/mydomain.com-0001.conf, there should be a commented-out line that indicates renew_before_expiry = 30 days. You can uncomment that line and set a different amount of time. The new amount of time that you set will be the amount of time before expiry when that particular certificate will be renewed by certbot renew. If it’s higher, the certificate will be renewed earlier; if it’s lower, the certificate will be renewed later.

1 Like

Ok cool then I will wait, and when cronjob runs again I will let you know!

Thanks a lot for all the time and work @schoen really learn a lot from you, really appreciate it!

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