准备

  • 一台服务器 (用于自动续期)
  • 一个邮箱
  • 一个 Google 帐号 (如果准备使用 Google Trust Service)
  • 或许需要一个代理
  • 脑子

安装

在下文所出现的所有代码示例中,均将 my@example.com 替换为你自己的邮箱

curl https://get.acme.sh | sh -s email=my@example.com

重启终端,即可使用 acme.sh 命令

CA 提供商

Let’s Encrypt

Let’s Encrypt 是 acme.sh 的默认 CA 提供商,无需额外配置即可使用

从其他 CA 切换到 Let’s Encrypt:

acme.sh --set-default-ca --server letsencrypt

ZeroSSL

注册一个 ZeroSSL 帐号

前往 https://app.zerossl.com/developer ,点击 EAB Credentials for ACME Clients 下方的 Generate,并保存好 EAB KIDEAB HMAC Key

最后,使用 acme.sh 注册并将默认 CA 切换到 zerossl

acme.sh --register-account --server zerossl \
    --eab-kid xxxxxxxxxxxx \
    --eab-hmac-key xxxxxxxxx
acme.sh --set-default-ca --server zerossl

Google Trust Service

在本段中,分别将示例代码中的 example-project 替换为你自己所想要的项目名称,example@gmail.com 替换为你的 Google 帐号

使用任意方法安装 Google Cloud CLI

登录 Google Account

gcloud auth login

创建一个 Google Cloud 项目并切换到该项目(如果没有)

gcloud projects create example-project
gcloud config set project example-project

给予自己权限

gcloud projects add-iam-policy-binding example-project \
  --member=user:example@gmail.com \
  --role=roles/publicca.externalAccountKeyCreator

启用 Public CA API

gcloud services enable publicca.googleapis.com

获取 EAB ID 和 HMAC

gcloud beta publicca external-account-keys create

保存好 b64MacKeykeyId,它们分别对应 EAB HMAC KeyEAB KID

最后,使用 acme.sh 注册并将默认 CA 切换到 google

acme.sh --register-account -m my@example.com --server google \
    --eab-kid xxxxxxx \
    --eab-hmac-key xxxxxxx

域名所有权验证方式

本节内的示例代码均不能直接运行,而是一个范本,用于介绍验证相关的参数,配合下文的申请部分使用

DNS API

本文仅有 Cloudflare 的用法
同时,来自 Freenom 的域名无法使用 Cloudflare API,故无法通过该方式验证

前往 Cloudflare API 令牌页面

点击 创建令牌 并选择 编辑区域 DNS 右边的 使用模板

区域资源 改为 所有区域

剩余选项保持默认,创建令牌

保存好刚创建的令牌,在服务器中配置环境变量

export CF_Key="xxxxxxxxxxx"
export CF_Email="mycf@example.com"
acme.sh --issue --dns dns_cf

xxxxxxxxxxx 替换为刚刚创建好的令牌,mycf@example.com 替换为你的 Cloudflare 登录邮箱

HTTP API

此方法需要服务器对公网开放 TCP 80 端口

Webroot

此方法适用于已有 Web 服务器的用户

acme.sh --issue -w /srv/www/example.com

/srv/www/example.com 替换为你自己的 Web 根目录

Standalone

让 acme.sh 自己作为一个临时的 Web 服务器用于验证

acme.sh --issue --standalone

申请证书

在示例代码的 --issue 后面加上你的所有权验证方式的参数,例如 --dns dns_cf--standalone

申请单个域名:

acme.sh --issue -d example.com

申请多个域名:

acme.sh --issue -d example1.com \
    -d example2.com \
    -d example3.com

申请通配符域名:

acme.sh --issue -d example.com \
    -d "*.example.com"

加入 --keylength ec-384 可以使用 ECC 证书

安装证书

acme.sh --install-cert -d example.com \
    --fullchain-file   /path/to/cert/cert.pem \
    --key-file          /path/to/cert/key.pem \

加入 --ecc 参数可以使用 ECC 证书