👤
Novice Handbook
  • Novice Handbook
  • Guide
  • Internet และ Web
    • HTML
  • Computer Language
    • Basic Computer Language (LV.1)
    • C Language (LV.1)
    • Python3 (LV.1)
  • Operating System
    • Linux
      • Basic Linux (LV.1)
  • TOOLS
    • Text Editor
      • Vim Editor
    • Source Control
      • GitLab
        • GitLab for small site (LV.1)
    • Container
      • Docker
        • Docker (LV.1)
        • Docker (LV.2)
      • Kubernetes
        • Kubernetes Intro (LV.0)
        • Kubernetes Basic (LV.1)
        • Kubernetes Intermediate (LV.2)
        • Helm (LV.2)
        • RKE2 (LV.3)
        • K3S (LV.3)
        • K3D (LV.3)
    • Repository
      • Harbor
        • Harbor for small site (LV.1)
        • Harbor for enterprise (LV.2)
    • Database
      • Redis
        • Redis on Docker Compose (LV.1)
        • Redis on Kubernetes (LV.2)
      • Elastic Stack
        • Elasticsearch & Kibana for small site (LV.1)
    • Observability
      • Prometheus
        • Prometheus for small site (LV.1)
        • Prometheus Operator (LV.2)
    • Security
      • Certbot (LV.1)
      • Falco
      • Hashicorp Vault
    • Collaboration
      • Nextcloud
Powered by GitBook
On this page
  • Requirement
  • การติดตั้ง
  • จด certificate
  • การทำ wildcard cert และ validate ผ่าน DNS

Was this helpful?

  1. TOOLS
  2. Security

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 ให้ส่งไปที่ admin@novice.solutions

Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@novice.solutions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.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.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): harbor.novice.solutions
Requesting a certificate for harbor.novice.solutions

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/harbor.novice.solutions/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/harbor.novice.solutions/privkey.pem
This certificate expires on 2025-01-14.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
We were unable to subscribe you the EFF mailing list. You can try again later by visiting https://act.eff.org.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

เสร็จแล้วจะได้ 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

certbot certonly --manual --preferred-challenges=dns --agree-tos -m admin@novice.solutions -d "*.novice.solutions"

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

Requesting a certificate for *.novice.solutions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.novice.solutions.

with the following value:

oDG4FGSTz9ZSEyWSTjcVHm3noshxmew-gMXqi65G5EE

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.novice.solutions.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

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

TYPE: TXT
NAME: _acme-challenge.novice.solutions
VALUE: oDG4FGSTz9ZSEyWSTjcVHm3noshxmew-gMXqi65G5EE

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

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

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/novice.solutions/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/novice.solutions/privkey.pem
This certificate expires on 2025-01-14.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PreviousSecurityNextFalco

Last updated 7 months ago

Was this helpful?