본문 바로가기
WebApp

[HTTPS] Certification 갱신 : certbot renew

by ds31x 2023. 9. 10.

certbot을 통한 무료인증서는 90일 갱신 주기를 가진다. (유료는 1년으로 알고 있다.)

즉, 3개월 마다 한번씩 갱신(renew)이 필요하다.

갱신을 위한 명령어는 다음과 같다.

sudo certbot renew
  • 특정 chain만을 갱신하려면, --cert-name 옵션으로 해당 chain 이름을 입력하면 된다: sudo certbot renew --cert-name code.ds31x.site
  • 만약 certification의 유효 기간이 많이 남은 경우, 갱신이 안된다.
    • 유효 기간에 상관없이 갱신하려면 --force-renewal 옵션을 붙여주면 된다.

갱신 수행 Test

갱신이 되는지 테스트만을 하고 싶다면 다음과 같이 --dry-run 옵션을 붙여서 수행하면 된다.

  • 성공할지 여부를 미리 확인해볼 수 있다.
  • 수동으로 갱신하는 경우 반드시 먼저 해보길 권한다.

crontab 을 이용한 스케쥴링.

다음 명령어로 crontab에서 수행한 작업들의 편집 시작.

sudo crotab -e

처음 실행시 편집기를 선택하라는 다음의 문구가 뜬다.

no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

Choose 1-4 [1]:
  • 초보자라면 vi보다 nano가 낫다 (메뉴를 읽으면서 처리 가능)
  • 하지만 vi는 꼭 익히길 권함.

editor를 선택하고 다음과 같은 라인을 추가한다.

0 0 1 * * certbot renew --renew-hook="sudo systemctl restart nginx"
  • 수행되는 시간은 0분, 0시, 1일, 매달, 요일상관없이 : 즉, 매달 1일 0시에 수행됨.
  • 수행되는 명령어는 `certbot renew --renew-hook="sudo systemctl restart nginx"임.
  • crontab -eroot 권한으로 수행되도록 sudo crontab -e로 수행했음을 잊지말자..

이 후 저장하고 다음의 명령어로 crontab을 갱신한다.

sudo service cron restart

참고로 crontab 편집기를 변경하려면 select-editor라는 명령어를 수행하면 다시 editor를 고를 수 있음.


스케쥴링 확인하기.

다음의 명령어를 수행하면 root 계정으로 스케쥴링된 jobs를 확인할 수 있음.

sudo crontab -l

다음과 같은 라인이 보이면 된다.

0 0 1 * * certbot renew --renew-hook="sudo systemctl restart nginx"

References

https://eff-certbot.readthedocs.io/en/stable/using.html#renewing-certificates

 

User Guide — Certbot 2.6.0 documentation

To view a list of the certificates Certbot knows about, run the certificates subcommand: Certificate Name shows the name of the certificate. Pass this name using the --cert-name flag to specify a particular certificate for the run, certonly, certificates,

eff-certbot.readthedocs.io

 

728x90

'WebApp' 카테고리의 다른 글

[HTTPS] certbot을 통한 nginx에서 HTTPS 설정.  (0) 2023.09.10
[HTTPS] certbot 사용법 : chain 삭제  (0) 2023.09.10
[Nginx] 설치 및 설정 추가.  (0) 2023.09.08
[WebApp] NginX 설정 관련 .  (0) 2023.08.01
[WebApp] CGI vs. WSGI  (0) 2023.07.31