Skip to main content

[Thủ Thuật Linux] Cài đặt SSL Certificates (Let's Encrypt) trên CentOS 7

Hướng dẫn lấy SSL Certificates miễn phí từ Let's Encrypt, để biết thêm chi tiết bạn có thể lên trực tiếp https://letsencrypt.org/

Chú ý rằng, thời hạn của CA chỉ có 90 ngày, vì vậy sau 90 ngày bạn cần phải cập nhập mới lại.

Bước 1 - Cài đặt Certbot Client package

# yum --enablerepo=epel -y install certbot

Bước 2 - Lấy Certificates

Yêu cầu: Apache httpd hoặc Nginx đang được chạy, nếu không bạn có thể đến tiếp bước 3 và đồng thời bạn cần có thể truy cập từ Internet đến máy chủ đang làm việc của bạn trên cổng 80 nhờ xác minh từ Let's Encrypt.


# for the option [--webroot], use a directory under the webroot on your server as a working temp
# -w [document root] -d [FQDN you'd like to get certs]
# FQDN (Fully Qualified Domain Name) : Hostname.Domainname
# if you'd like to get certs for more than 2 FQDNs, specify all like below
# ex : if get [srv.world] and [www.srv.world]
# ⇒ specify [-d srv.world -d www.srv.world]
[root@www ~]# certbot certonly --webroot -w /var/www/html -d www.srv.world
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices) 
# for only initial using, register your email address and agree to terms of use
# specify valid email address
(Enter 'c' to cancel): root@mail.srv.world 
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
# agree to the terms of use
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing 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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
# answer Yes or No
(Y)es/(N)o: Y
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.srv.world
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.srv.world/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.srv.world/privkey.pem
   Your cert will expire on 2018-05-22. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

# success if [Congratulations] is shown
# certs are created under the [/etc/letsencrypt/live/(FQDN)/] directory

# cert.pem       ⇒ SSL Server cert(includes public-key)
# chain.pem      ⇒ intermediate certificate
# fullchain.pem  ⇒ combined file cert.pem and chain.pem
# privkey.pem    ⇒ private-key file

Bước 3 - Xác minh khi không có Web Server

Nếu không có Web Server nào đang chạy trên server đang làm việc của bạn, bạn có thể nhận được Certificates bằng cách sử dụng tính năng Certbot của Web Server. Dù sao, bạn cần có thể truy cập từ Internet đến server đang hoạt động của bạn trên cổng 80 để xác minh từ Let's Encrypt.

[root@www ~]# certbot certonly --standalone -d mail.srv.world
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mail.srv.world
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mail.srv.world/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mail.srv.world/privkey.pem
   Your cert will expire on 2018-05-22. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - 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

Bạn có thể thêm các tùy chọn:

[--standalone] : sử dụng tính năng Certbot's Web Server 
-d  : nếu muốn FQDN (Fully Qualified Domain Name) lấy chứng chỉ

Bước 4 - Cập nhập lại Certificates đã tồn tại 

 

Cập nhật tất cả các chứng chỉ hết hạn dưới 30 ngày, nếu bạn muốn cập nhật chứng chỉ đã hết hạn hơn 30 ngày, hãy thêm tùy chọn [--force-renew] 

[root@www ~]# certbot renew