Certbot Auto Install Command (No Prompts) - Tự động cài SSL Let’s Encrypt không cần nhập tay

Views: 3 29/05/2026 19:13
Certbot Auto Install Command (No Prompts) - Tự động cài SSL Let’s Encrypt không cần nhập tay

Certbot hỗ trợ chế độ cài đặt SSL hoàn toàn tự động bằng tham số command line, giúp bạn không cần nhập email, domain hay xác nhận thủ công trong quá trình cài SSL.

Cách này rất phù hợp cho:

  • VPS tự động deploy

  • Script cài server

  • CI/CD

  • Hosting nhiều website

  • Tự động hóa quản trị hệ thống

1. Cài Certbot trên Ubuntu

Ubuntu + Nginx

sudo apt update
sudo apt install certbot python3-certbot-nginx -y

Ubuntu + Apache

sudo apt update
sudo apt install certbot python3-certbot-apache -y

2. Certbot Auto Install Command (No Prompts)

Dành cho Nginx

sudo certbot --nginx \
-d example.com \
-d www.example.com \
--non-interactive \
--agree-tos \
-m admin@example.com \
--redirect

Dành cho Apache

sudo certbot --apache \
-d example.com \
-d www.example.com \
--non-interactive \
--agree-tos \
-m admin@example.com \
--redirect

3. Giải thích các tham số

Tham số

Ý nghĩa

--nginx

Tự động cấu hình SSL cho Nginx

--apache

Tự động cấu hình SSL cho Apache

-d

Domain cần cài SSL

--non-interactive

Không hỏi nhập tay

--agree-tos

Tự động đồng ý điều khoản

-m

Email nhận thông báo SSL

--redirect

Tự động redirect HTTP sang HTTPS

4. Ví dụ thực tế

SSL cho 1 domain

sudo certbot --nginx \
-d mydomain.com \
--non-interactive \
--agree-tos \
-m admin@mydomain.com \
--redirect

SSL cho nhiều subdomain

sudo certbot --nginx \
-d example.com \
-d www.example.com \
-d api.example.com \
-d mail.example.com \
--non-interactive \
--agree-tos \
-m admin@example.com \
--redirect

5. Kiểm tra SSL đã cài thành công

sudo certbot certificates

Hoặc kiểm tra trực tiếp:

https://yourdomain.com

6. Kiểm tra Auto Renew SSL

Let’s Encrypt có thời hạn 90 ngày. Certbot thường sẽ tự renew bằng systemd timer hoặc cron.

Kiểm tra bằng lệnh:

sudo certbot renew --dry-run

Nếu không có lỗi nghĩa là auto renew hoạt động bình thường.

7. Kiểm tra Timer Renew

systemctl list-timers | grep certbot

8. Một số lỗi thường gặp

Domain chưa trỏ IP

Lỗi:

DNS problem: NXDOMAIN

Cần kiểm tra:

dig yourdomain.com

Port 80 đang bị chặn

Certbot cần xác thực qua HTTP port 80.

Mở firewall:

sudo ufw allow 80
sudo ufw allow 443

Nginx config lỗi

Kiểm tra trước khi chạy Certbot:

sudo nginx -t

9. Gợi ý script tự động hoàn toàn

 

#!/bin/bash

DOMAIN="example.com"
EMAIL="admin@example.com"

apt update
apt install certbot python3-certbot-nginx -y

certbot --nginx \
-d $DOMAIN \
--non-interactive \
--agree-tos \
-m $EMAIL \
--redirect

Lưu file:

install_ssl.sh

Cấp quyền chạy:

chmod +x install_ssl.sh

Thực thi:

./install_ssl.sh

 

Chúc các bạn thành công

 

certbot auto install certbot no prompts letsencrypt auto install certbot ssl ubuntu auto ssl nginx apache certbot command line cài ssl tự động linux certbot nginx ubuntu certbot apache ubuntu