Certbot (LV.1)

Certbot คือเครื่องมืออัตโนมัติที่ช่วยในการรับและติดตั้งใบรับรอง SSL/TLS จาก Let's Encrypt ซึ่งเป็นผู้ออกใบรับรองฟรี โดยเครื่องมือ Certbot จะทำหน้าที่ตั้งค่าและต่ออายุใบรับรองโดยอัตโนมัติสำหรับเว็บไซต์ของคุณ ทำให้เว็บไซต์สามารถใช้ HTTPS เพื่อรักษาความปลอดภัยข้อมูลที่รับส่งได้

Certbot สามารถทำงานได้กับเว็บเซิร์ฟเวอร์ที่ได้รับความนิยม เช่น Apache และ Nginx และช่วยจัดการขั้นตอนที่ซับซ้อนในการขอใบรับรอง SSL/TLS โดยไม่จำเป็นต้องมีความรู้เชิงลึกเกี่ยวกับระบบความปลอดภัย นอกจากนี้ Certbot ยังมีฟังก์ชันที่ช่วยในการต่ออายุใบรับรองโดยอัตโนมัติเพื่อให้เว็บไซต์ของคุณใช้งาน HTTPS ได้อย่างต่อเนื่อง

Requirement

เพื่อที่จะจด certificate อย่างง่าย เครื่องจำเป็นต้องไม่มีการใช้งาน port 80 ในระหว่างจด certificate และมีการ map public domain name ไว้ และสามารถเข้าถึงได้จาก public

การติดตั้ง

sudo apt update
sudo apt install -y certbot

จด certificate

ทำการจด certificate

sudo certbot certonly

หลังจากนั้นจะขึ้น prompt มา

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Runs an HTTP server locally which serves the necessary validation files under
the /.well-known/acme-challenge/ request path. Suitable if there is no HTTP
server already running. HTTP challenge only (wildcards not supported).
(standalone)
2: Saves the necessary validation files to a .well-known/acme-challenge/
directory within the nominated webroot path. A seperate HTTP server must be
running and serving files from the webroot path. HTTP challenge only (wildcards
not supported). (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

อันแรกจะเป็นการให้ certbot เปิด HTTP server ขึ้นมา ซึ่งใช้ได้ในกรณีที่ไม่มี service ใดใช้ port 80 อยู่ ส่วนกรณีที่สองคือ หากเรามี web server อยู่แล้ว เราต้องไปสร้าง file และ content ให้ web server เรา response ตรงกับที่ Let's encrypt จะมา challenge

ในกรณีนี้ให้เราเลือกวิธีแรก ซึ่งง่ายที่สุด

ตัวอย่างดังต่อไปนี้เป็นการจด cert harbor.novice.solutions และหาก Let's Encrypt จะมีส่งแจ้งเตือน cert expire ให้ส่งไปที่ [email protected]

เสร็จแล้วจะได้ cert มา

เวลาเรียกใช้ เราควร refer มาที่ path /etc/letsencrypt/live/xxx ไม่ควร move file ไปที่อื่น หรือชี้ไปที่ /etc/letsencrypt/archive/xxx โดยตรง เพราะที่ archive จะมีการเปลี่ยนแปลง เวลา renew cert


การทำ wildcard cert และ validate ผ่าน DNS

ในบางกรณี เราอาจจะอยากทำ wildcard cert ซึ่งการทำ wildcard cert ผู้ดำเนินการจำเป็นต้องเป็นเจ้าของ domain นั้น และสามารถ config เพื่อ set ค่าบน dns server ขณะนั้นได้

ตัวอย่าง command

หลังจากนั้น Let's Encrypt จะให้เรา set DNS record เพื่อ challenge

จากตัวอย่าง เราต้องไป set record ดังนี้

เมื่อ config เรียบร้อย ให้ enter

ถ้าผ่านจะขึ้นข้อความดังนี้

Last updated

Was this helpful?