certbot 명령어(인증서 관리 및 삭제)

Alma Linux에서 이 사이트에 Certbot 설치 및 갱신 설치를 해 진행하는 중 인증서 삭제 후 재설치를 할 이유가 생겨 삭제와 함께 나머지 Certbot 명령어 사용법에 대해 체크하게 되었습니다.

certbot 명령어는 다음 페이지에서 확인했습니다.

✅ certbot 명령어: 인증서 관리

사용 중인 인증서 목록을 보려면 다음 명령어를 입력합니다.

certbot certificates

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: mydomain.com
    Serial Number: 4b5c738962b78627df66143f3fc9f86c1d7
    Key Type: ECDSA
    Domains: mydomain.com
    Expiry Date: 2025-06-04 09:26:03+00:00 (VALID: 65 days)
    Certificate Path: /etc/letsencrypt/live/mydomain.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/mydomain.com/privkey.pem
  Certificate Name: tozisin.com
    Serial Number: 46dc157eaec46266d5a0b1b56a329efd4e7
    Key Type: ECDSA
    Domains: mydomain2.com
    Expiry Date: 2025-05-01 08:39:00+00:00 (VALID: 31 days)
    Certificate Path: /etc/letsencrypt/live/mydomain2.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/mydomain2.com/privkey.pem
  Certificate Name: uknew.co
    Serial Number: 314714a3a2efc3f72a5c2a592b74f0ded80
    Key Type: ECDSA
    Domains: uknew.co
    Expiry Date: 2025-05-04 08:43:10+00:00 (VALID: 34 days)
    Certificate Path: /etc/letsencrypt/live/uknew.co/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/uknew.co/privkey.pem

기존 인증서 재생성 및 업데이트

certonly 명령어는 인증서를 처음 설치할 때 사용하지만 옵션에 따라 인증서 재생성과 업데이트를 진행할 때도 사용합니다.

certonly이미 동일한 도메인 이름을 포함하는 기존 인증서가 있는 경우에도 또는 run하위 명령을 사용하여 단일 새 인증서 생성을 요청할 수 있습니다.

run이미 존재하는 인증서 이름을 지정 하거나 인증서가 요청되는 경우 certonlyCertbot은 기존 인증서를 업데이트합니다. 그렇지 않으면 새 인증서가 생성되고 지정된 이름이 할당됩니다.

--force-renewal--duplicate, 및 옵션 --expand은 기존 인증서와 동일한 이름으로 인증서를 다시 만들 때 Certbot의 동작을 제어합니다. 요청된 동작을 지정하지 않으면 Certbot이 의도한 바를 물을 수 있습니다.

--force-renewalCertbot에 기존 인증서와 동일한 도메인을 사용하여 새 인증서를 요청하라고 지시합니다. 각 도메인은 .을 통해 명시적으로 지정해야 합니다 -d. 성공하면 이 인증서는 이전 인증서와 함께 저장되고 심볼릭 링크(” live” 참조)가 새 인증서를 가리키도록 업데이트됩니다. 이는 특정 개별 인증서를 갱신하는 유효한 방법입니다.

--duplicateCertbot에게 기존 인증서와 동일한 도메인을 가진 별도의 관련 없는 인증서를 만들라고 지시합니다. 이 인증서는 이전 인증서와 완전히 별도로 저장됩니다. 대부분의 사용자는 일반적인 상황에서 이 명령을 실행할 필요가 없습니다.

--expandCertbot에 기존 인증서를 모든 이전 도메인과 하나 이상의 추가 새 도메인을 포함하는 새 인증서로 업데이트하라고 지시합니다. 이 --expand옵션을 사용하여 -d모든 기존 도메인과 하나 이상의 새 도메인을 지정합니다.

certbot 명령어 사용자 가이드 참조 내용
웹 보안(Web Security)

✅ 인증서 취소 및 삭제

확인 결과 인증서 취소는 인증서 취소 후 다음 인증서 자동 갱신 때 갱신이 진행되기 떄문에 취소 진행 시 삭제를 같이 진행할지를 묻고 인증서 삭제 명령어는 인증서를 바로 삭제합니다.

🔲 인증서 취소

certbot revoke --cert-name example.com
# 인증서 취소 #

플래그를 사용하여 인증서를 해지하는 이유를 지정할 수도 있습니다 reason. 이유에는 unspecified기본값인 keycompromiseaffiliationchangedsuperseded, 및 cessationofoperation: 가 포함됩니다.

certbot revoke --cert-name example.com --reason affiliationchanged

🔲 인증서 삭제

인증서 삭제는 delete 명령어를 사용합니다.

certbot delete --cert-name example.com
# or to choose from a list:
certbot delete

바로 삭제를 진행할 경우 서버가 정상적으로 작동하지 않을 수 있다는 메시지를 확인했고 기존에 설치된 내역 확인 후 안전하게 삭제하는 방법을 확인했습니다. 삭제 진행을 할 때 해당 내역들을 함께 삭제 진행해주면 되겠습니다.

#인증서에 대한 모든 참조 찾기 # 
 bash -c 'grep -R live/mydomain.com  /etc/{nginx,httpd,apache2}'
/etc/httpd/conf.d/ssl.conf:    SSLCertificateFile /etc/letsencrypt/live/mydomain.com/cert.pem
/etc/httpd/conf.d/ssl.conf:    SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
/etc/httpd/conf.d/ssl.conf:    SSLCertificateChainFile /etc/letsencrypt/live/mydomain.com/chain.pem
/etc/httpd/conf.d/ssl.conf:    SSLCACertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
grep: /etc/httpd/run/cgisock.360194: No such device or address
grep: /etc/apache2: No such file or directory

직접 삭제 진행을 해 보겠습니다.

~]# certbot delete --cert-name mydomain.com

The following certificate(s) are selected for deletion:

  * mydomain.com

WARNING: Before continuing, ensure that the listed certificates are not be              ing
used by any installed server software (e.g. Apache, nginx, mail servers).
Deleting a certificate that is still being used will cause the server soft              ware
to stop working. See https://certbot.org/deleting-certs for information on
deleting certificates safely.

Are you sure you want to delete the above certificate(s)? Y

Deleted all files relating to certificate mydomain.com.

~]# httpd -t
AH00526: Syntax error on line 231 of /etc/httpd/conf.d/ssl.conf:
SSLCertificateFile: file '/etc/letsencrypt/live/mydomain.com/cert.pem' does not exist or is empty

위와 같은 에러가 나니 apache 재 시작 전에 해당 경로 설정들을 삭제 해 주도록 합니다. certbot 명령어의 기본 내용과 삭제 위주로 알아 봤습니다.

SSL TLS 보안인증서

Similar Posts