เมื่อมีการยกเลิกการใช้งานซับโดเมน (Subdomain) หรือย้ายเซิร์ฟเวอร์ออกไปแล้ว หากปล่อยให้ Certbot พยายามต่ออายุใบรับรอง (SSL/TLS Certificate) ต่อไปเรื่อยๆ จะส่งผลให้ระบบแจ้งเตือนข้อผิดพลาด Renewal Failure ทุกครั้งที่สคริปต์อัตโนมัติทำงาน
บทความนี้จะแนะนำขั้นตอนการลบ Certificate ที่ไม่ต้องการอย่างถูกต้อง พร้อมวิธีตรวจสอบความเรียบร้อยของระบบครับ
ทำไมไม่ควรลบไฟล์ Certificate ด้วยคำสั่ง rm โดยตรง?
Certbot มีการเก็บข้อมูลเชื่อมโยงกันในหลายไดเรกทอรี ได้แก่:
/etc/letsencrypt/live/(Symlink ไปยังไฟล์ล่าสุด)/etc/letsencrypt/archive/(ไฟล์ Key และ Certificate จริง)/etc/letsencrypt/renewal/(ไฟล์การตั้งค่าการ Renew)
หากใช้คำสั่ง rm -rf ลบเฉพาะบางโฟลเดอร์ ไฟล์คอนฟิกในการต่ออายุจะยังคงค้างอยู่ และทำให้เกิด Error เมื่อรันคำสั่ง certbot renew
ขั้นตอนการลบ Certificate ด้วย Certbot CLI
1. ตรวจสอบรายชื่อ Certificate ทั้งหมดในระบบ
ก่อนทำการลบ ให้เช็กชื่อของ Certificate (Certificate Name) ที่ต้องการลบด้วยคำสั่งsudo certbot certificates
ตัวอย่างผลลัพธ์
JavaScript
Found the following certs:
Certificate Name: example.com
Serial Number: 4003...
Domains: example.com www.example.com
Expiry Date: 2026-11-10 12:00:00+00:00 (VALID: 88 days)
Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem
Certificate Name: old-subdomain.example.com
Serial Number: 3002...
Domains: old-subdomain.example.com
Expiry Date: 2026-09-01 10:00:00+00:00 (INVALID: EXPIRED)
Certificate Path: /etc/letsencrypt/live/old-subdomain.example.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/old-subdomain.example.com/privkey.pem