리눅스

우분투에서 Certbot을 사용하여 Let's Encrypt SSL 인증서를 생성하는 방법

변군이글루 2024. 3. 28. 15:28
반응형

우분투에서 Certbot을 사용하여 Let's Encrypt SSL 인증서를 생성하는 방법

Certbot 설치

우분투 패키지 관리자를 사용하여 Certbot을 설치합니다.

sudo apt-get update
sudo apt-get install -y certbot
certbot --version
$ certbot --version
certbot 1.21.0

인증서 발급

Certbot을 사용하여 SSL 인증서를 발급합니다. 도메인 이름은 실제 도메인으로 변경해야 합니다.

sudo certbot certonly --standalone --agree-tos --email email@example.com -d testssl.example.com
더보기
더보기

---

$ sudo certbot certonly --standalone --agree-tos --email email@example.com -d testssl.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n
Account registered.
Requesting a certificate for testssl.example.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/testssl.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/testssl.example.com/privkey.pem
This certificate expires on 2024-06-26.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

---

인증서 정보 확인

sudo certbot certificates
$ sudo certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: testssl.example.com
    Serial Number: 33c1488e5c7838a0f74ad0e2723cc5bb6bf
    Key Type: RSA
    Domains: testssl.example.com
    Expiry Date: 2024-06-26 00:13:43+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/testssl.example.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/testssl.example.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

인증서 유효성 확인

sudo openssl x509 -in /etc/letsencrypt/live/도메인이름/cert.pem -text -noout
$ sudo openssl x509 -in /etc/letsencrypt/live/testssl.example.com/fullchain.pem -text -noout                   
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            03:3c:14:88:e5:c7:83:8a:0f:74:ad:0e:27:23:cc:5b:b6:bf
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = US, O = Let's Encrypt, CN = R3
        Validity
            Not Before: Mar 28 00:13:44 2024 GMT
            Not After : Jun 26 00:13:43 2024 GMT
        Subject: CN = testssl.example.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:
                    00:97:bf:5f:a9:90:d8:56:82:b3:61:07:04:7f:b2:
 ...
    Signature Algorithm: sha256WithRSAEncryption
    Signature Value:
        63:49:fc:28:3c:e2:a2:72:59:92:97:d2:1d:aa:6b:92:8b:dd:
        4a:ca:a3:e1:fd:49:b0:d8:1c:4f:9d:fd:03:96:e4:79:e2:c1:
        c3:47:b5:6a

인증서 설정

Certbot은 발급된 인증서와 개인 키를 /etc/letsencrypt/live/testssl.example.com/ 디렉토리에 저장합니다.

  • fullchain.pem: cert.pem 및 chain.pem의 내용을 합친 파일
    • cert.pem: SSL 인증서 파일
    • chain.pem: 인증서 체인 파일 (Let's Encrypt의 중간 인증서)
  • privkey.pem: SSL 개인 키 파일

웹 서버 설정

발급된 SSL 인증서를 웹 서버에 적용하여 HTTPS를 활성화합니다.

인증서 갱신 설정

Certbot을 사용하여 발급된 인증서는 90일마다 만료됩니다. 따라서 인증서를 자동으로 갱신하는 것이 좋습니다. Certbot은 cron 작업을 사용하여 이를 자동화할 수 있습니다.

sudo crontab -e
0 0 * * * certbot renew --quiet

Let's Encrypt SSL 인증서를 우분투에서 생성하고 웹 서버에 적용할 수 있습니다.

와일드카드 SSL 인증서를 받는 방법

DNS-01 확인 방법 선택

Let's Encrypt는 와일드카드 인증서를 발급하기 위해 도메인의 소유를 확인하는 DNS-01 확인 방법을 사용합니다. 이 방법은 서버가 아닌 DNS 레코드를 통해 확인합니다.

와일드카드 인증서 발급

Certbot을 사용하여 와일드카드 인증서를 발급하려면 다음 명령어를 사용합니다.

sudo certbot certonly --manual --preferred-challenges=dns -d example.com -d *.example.com

DNS 확인 및 인증

Certbot은 DNS 확인을 위해 특정 텍스트 레코드를 도메인의 DNS 설정에 추가하라는 지침을 제공합니다. 이를 따르고 확인이 완료되면 Certbot이 와일드카드 SSL 인증서를 발급합니다.

인증서 사용

Certbot은 인증서 및 개인 키를 /etc/letsencrypt/live/example.com/ 디렉토리에 저장합니다. 이 인증서를 웹 서버 설정에 추가하여 HTTPS를 활성화합니다.

 

와일드카드 SSL 인증서를 받기 위해서는 DNS에 대한 제어 권한이 있어야 하며 Certbot이 DNS 설정을 업데이트할 수 있어야 합니다. 필요한 경우 DNS 서비스 제공업체에 대한 API 키를 사용하여 Certbot이 자동으로 DNS 레코드를 업데이트할 수도 있습니다.

 

728x90
반응형