Linux

Centos S9 - 무료 SSL 인증서 - Letsencrypt 발급 받기

Ryan's Tech Note 2023. 2. 27. 22:40

Letsencrypt 무료 SSL 인증서를 다음과 같이 신청한다.

dnf --enablerepo=epel -y install certbot 

certbot certonly --webroot -w /var/www/mydomain.com/webapp -d www.mydomain.com

 

약관에 동의하냐 ? 관련 메일을 받아 보겠냐 ? Y 를 입력하고 통과한다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): ryan.min@mydomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf.
 You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: y
Account registered.
Requesting a certificate for 
www.mydomain.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/
www.mydomain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/
www.mydomain.com/privkey.pem
This certificate expires on 2023-05-28.
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 


 

하위 도메인이 있다면 (예: mail 등), apache 를 정지하고 다음과 같이 신청한다.

systemctl stop httpd

certbot certonly --standalone -d mail.mydomain.com


추가로 응답이 필요없이 완료된다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for mail.mydomain.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mail.mydomain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/mail.mydomain.com/privkey.pem
This certificate expires on 2023-05-28.
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 

위 경로에 인증서 들이 다운로드 되어 있다.

이 인증서를 Web Server 또는 WAS 에 등록하면 된다.

 

참조 링크 : https://www.server-world.info/en/note?os=CentOS_7&p=ssl&f=2

 


 

무료 인증서는 3개월 후에 만료되는데, cron 에 등록해 놓고 3개월마다 자동 갱신되도록 한다.

현재 시점을 기준으로 몇월 몇일에 업데이트 할지 정하면 된다.

vi /etc/crontab

# 매년 3월, 6월, 9월, 12월 1일 오전 2시 00에 인증서를 갱신하라
0 2 1 Mar,Jun,Sep,Dec * /usr/bin/certbot renew

 


2025-5-22 추가 내용

dovecot 에서 갑자기 인증서 관련 오류가 발생해서 다음 방법으로 해결하였다.

1. 권한 문제 해결

Let's Encrypt 인증서 디렉토리의 권한이 Dovecot 서비스 사용자에게 적절하지 않습니다. Dovecot은 보통 dovecot 또는 mail 사용자로 실행되며 이 사용자가 인증서를 읽을 수 있어야 합니다.

 
bash
# Dovecot 사용자 확인
grep -i user /etc/dovecot/conf.d/10-master.conf

# 인증서 디렉토리에 대한 액세스 권한 부여
# 방법 1: Dovecot 그룹에 인증서 디렉토리 읽기 권한 부여
setfacl -R -m g:dovecot:rx /etc/letsencrypt/archive/mail.terple.com/
setfacl -R -m g:dovecot:rx /etc/letsencrypt/live/mail.terple.com/

# 또는 방법 2: 인증서 복사 (권장되지 않음)
# mkdir -p /etc/dovecot/certs/
# cp /etc/letsencrypt/live/mail.terple.com/*.pem /etc/dovecot/certs/
# chown -R dovecot:dovecot /etc/dovecot/certs/

2. 프로세스 충돌 문제 해결

PID 파일 관련 오류가 발생하고 있습니다:

 
bash
# PID 파일 확인 및 제거
rm /run/dovecot/master.pid

# 실행 중인 Dovecot 프로세스 확인
ps aux | grep dovecot

# 실행 중인 프로세스 종료 (필요한 경우)
kill -9 55187  # 로그에 나온 PID 번호

이 두 문제를 해결한 후 다시 서비스를 시작해보세요:

 
bash
systemctl start dovecot

만약 SELinux가 활성화되어 있다면 인증서 파일에 대한 컨텍스트 설정도 필요할 수 있습니다:

 
bash
restorecon -Rv /etc/letsencrypt/

 

바로 위에 줄이 해결의 핵심 부분이었다.


 

도움이 되었다면 공감과 댓글 한번 부탁드립니다.