Ubuntu Server / Let’s Encrypt 무료 SSL 인증서 발급 받기

Ubuntu Server에서 Apache Web Server를 사용하는 경우 Let’s Encrypt 인증서 발급 받는 방법입니다.

Apache용 Certbot 설치

Ubuntu Server 20.04, Ubuntu Server 22.04

sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

Ubuntu Server 18.04

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt upgrade
sudo apt install certbot python3-certbot-apache

Ubuntu Server 16.04

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt upgrade
sudo apt install python-certbot-apache

인증서 발급

  • abc.com 인증서를 발급하고 설정 파일을 생성합니다.
sudo certbot --apache -d abc.com
  • abc.com과 www.abc.com 인증서를 동시 발급하고 설정 파일을 생성합니다.
sudo certbot --apache -d abc.com -d www.abc.com
  • abc.com 인증서만 발급합니다.
sudo certbot certonly --apache -d abc.com
  • 와일드 카드 인증서만 발급합니다. DNS에 레코드를 추가하는 과정이 있습니다.(이처럼 만든 인증서는 certbot renew로 갱신되지 않습니다. 다시 발급받아야 합니다.)
sudo certbot certonly --manual --preferred-challenges=dns -d abc.com -d *.abc.com

인증서 갱신

Let’s Encrypt 인증서 유효 기간은 90일이고, 만료일 30일 전부터 갱신이 가능합니다.

  • 갱신 가능한 인증서를 갱신합니다.
sudo certbot renew

인증서 삭제

  • abc.com 인증서를 삭제합니다.
sudo certbot delete --cert-name abc.com

Cron으로 자동 갱신

  • crontab에 다음을 추가하면 매일 새벽 4시에 갱신을 시도합니다.
0 4 * * * certbot renew --post-hook "service apache2 reload"