Certbot으로 무료 인증서 발급 받기

by digipine posted Sep 03, 2020
?

Shortcut

PrevPrev Article

NextNext Article

ESCClose

Larger Font Smaller Font Up Down Go comment Print

Let’s Encrypt? Certbot?

처음에 햇갈린 것이 저 두개가 무엇인지에 대한 것이었습니다.

Let’s Encrypt의 경우 Https의 확산을 늘리기 위한 취지로 시작된 비영리 프로젝트입니다.
Let’s Encrypt 공식 홈페이지에서 좀 더 자세한 정보를 확인할 수 있습니다.

Certbot은 Let’s Encrypt 인증서를 자동으로 발급 및 갱신을 해주는 봇 프로그램입니다.
certbot 공식 홈페이지에서 운영할 소프트웨어(Apache, Nginx, etc)와 OS에 따른 설치 방법을 제공합니다.
필요하신 분은 공식 홈페이지에서 알맞는 설치 방법을 확인하시기 바랍니다.

시작 전에…
Let’s Encrypt 인증서 발급 프로세스는 아래와 같습니다.

  1. 인증서 요청
  2. 도메인에 대한 소유권 확인
  3. 발급

위의 세 가지를 거치는데 이것을 자동으로 수행해주는 프로그램이라 생각하면 됩니다.
이번 포스팅에서는 Certbot을 이용해서 인증서를 발급받아 보도록 하겠습니다.

  • Certbot을 이용해 인증서를 받기 전 준비물은 서비스할 도메인 주소서비스를 운용하는 서버 가 필수적으로 필요합니다.

 

Certbot 설치

먼저 우분투(16.04)에서 Certbot을 설치해야 합니다.

$ sudo apt-get update #apt-get 업데이트
$ sudo apt-get install software-properties-common #선행 소프트웨어 설치
$ sudo add-apt-repository ppa:certbot/certbot #저장소 추가
$ sudo apt-get update #apt-get 업데이트

여기까지 하면 apt-get에서 certbot을 설치할 수 있는데 (아직 certbot 설치 전) 설치를 하기 전에 고려할 것이 있습니다.

Certbot을 통해서 인증서를 발급받을 위 프로세스에서 2번 항목인 소유권 확인이 있습니다.

왜 도메인 소유권을 확인하는지 궁금하실 수 있습니다.

이는 클라이언트에서는 상대방 서버가 진짜 통신하려는 사용자 서버인지를 검증하기 위함입니다.
예를 들어 소유하지 않은 도메인에 대한 인증서를 신뢰성이 있는 발급기관으로부터 발급받았다 한다면 해당 도메인을 이용하여 가짜 서버로 연결되게 할 수 있습니다.
만약 도메인 검증을 안한다면, 악의를 가진 사람이 국내에서 유명한 naver.com이나 daum.net 등의 도메인으로 인증서를 발급받게 되고, 해당 도메인에 약간의 조작을 통해서 자신이 만든 해킹을 목적으로 하는 서버에 연결하게끔 할 수 있게 됩니다.
좀 더 자세한 사항은 StartSSL 사건을 검색해보시면 이해가 더욱 쉽습니다.

다시…
이 소유권 확인을 위해 Certbot에서는 두 가지 인증 방법을 제공합니다.

  1. Standalone 방식

    이 방법은 Certbot이 간이 웹 서버를 돌려 도메인 인증 요청을 처리하는 방식입니다.
    하지만 인증용 간이 서버가 80, 443번 포트를 사용하기 때문에 운영 중인 서버가 해당 포트를 쓰게 된다면, 발급 또는 갱신 시 마다 잠시 서버를 내려야 하는 문제가 있습니다.
    물론 해당 포트를 사용하지 않는다면 이 방법을 사용하셔도 무방합니다.

  1. Webroot 방식

    이 방법은 도메인 인증을 위해 외부에서 접근 가능한 경로를 제공하고, Let’s Encrypt 측에서 해당 경로로 접속해 인증을 하는 방식입니다.
    이 방식을 사용할 경우 1번 방식의 서비스 종료는 하지 않아도 됩니다.

이번 포스팅에서는 2번을 사용하여 진행을 할 것입니다.

저의 경우 Java -jar로 수행을 하고, 향후 앞단에 서버를 하나 둘 예정이어서 Apache를 하나 설치하여 진행하였습니다.

이제 설치부분으로 넘어와서…

$ sudo apt-get install certbot #certbot 설치

 

Certbot으로 인증서 발급받기

설치를 완료한 뒤에는 위에서 언급한 도메인 인증 방법을 선택하여 발급받아야 합니다.

1번 방식을 사용할 경우…

sudo certbot certonly –standalone -d [도메인명]

2번 방법을 사용할 경우

sudo certbot certonly –webroot -w [접근 가능 경로] -d [도메인명]

몇 가지 옵션을 설명하자면…

  • -w : webroot 인증 방식 시 인증 파일을 생성할 기준 폴더를 명시합니다.
    예시로 Apache의 경우 /var/www/html 와 같은 경로를 의미합니다.
    
  • -d : 인증서를 적용할 도메인 명을 적어줍니다.
    만약 2개 이상을 작성할 경우 -d [도메인 명] -d [도메인 명] 으로 복수 작성 가능합니다.
    
  • certonly : 인증서 생성 및 갱신만 진행하는 옵션
  • –work-dir : 작업 디렉토리 지정 옵션 (기본값: /var/lib/letsencrypt)
  • –logs-dir : 로그 디렉토리 지정 옵션 (기본값: /var/log/letsencrypt)
  • –config-dir : 설정파일 및 인증서가 저장되는 디렉토리 지정하는 옵션 (기본값: /etc/letsencrypt)

아래는 실제 사용된 명령어 및 결과입니다.
주요 정보 및 민감정보는 임의 수정을 하였고, 실행하는 OS 및 구성에 따라 아래와는 다르게 결과가 출력될 수 있습니다.

ubuntu@ip-000-00-00-000:/var/www/html$ sudo certbot certonly --webroot -w /var/www/html -d [mydomain]

Saving debug log to /var/log/letsencrypt/letsencrypt.log
​​​​​​Plugins selected: Authenticator webroot, Installer None
​​​​​​Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [등록 시 사용할 이메일 주소 입력]
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org


-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A 

-------------------------------------------------------------------------------
Would you be willing 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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y

Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for member.tachyontech.co.kr
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/member.tachyontech.co.kr/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/member.tachyontech.co.kr/privkey.pem
   Your cert will expire on 2018-06-16. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
​​​​​​
secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

ubuntu@ip-000-00-00-000:/var/www/html$

 

위에서 결과 중 IMPORTANT NOTES: 아래에 Congratulations! 라는 멘트가 있으면 인증서 발급에 성공한 것입니다.
발급받은 인증서를 확인하려면 아래의 명령어를 통해 확인 가능합니다.

1
2
3
4
5
6
7
8
9
10
11
12
ubuntu@ip-000-00-00-000:/var/www/html$ sudo certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Found the following certs:
  Certificate Name: [name]
    Domains: [name]
    Expiry Date: 2018-06-16 11:50:35+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/[name]/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/[name]/privkey.pem
-------------------------------------------------------------------------------
ubuntu@ip-000-00-00-000:/var/www/html$

이로써 인증서 발급에 대한 설명은 끝났습니다.
간략하게 정리를 하면 아래와 같습니다.

  1. 도메인 및 서버 준비
  2. certbot 설치
  3. certbot으로 인증서 발급

Articles

1 2 3 4 5 6