栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ubuntu 使用 ACME 工具免费申请 SSL 证书

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu 使用 ACME 工具免费申请 SSL 证书

安转 ACME

安装依赖

sudo apt install socat

安装时可以提供邮箱地址

# 切换至 root 用户(下面使用 HTTP 验证时需要 root 权限)
sudo -i 
# wget 默认下载到文件, 使用 '-' 表示输出到标准输出, 经管道提供给 sh 执行
wget -O - https://get.acme.sh | sh -s email=my@example.com
或者
# curl 默认下载到标准输出
curl https://get.acme.sh | sh -s email=my@example.com

安装会完成以下内容:

  1. 创建安装目录 ~/.acme.sh
  2. 创建别名 alias acme.sh=~/.acme.sh/acme.sh
  3. 创建一个定时任务
$ crontab -l
21 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

最后不要忘了 source ~/.bashrc, 不然别名没有生效


如果想卸载 ACME 工具, 可以执行:

acme.sh --uninstall
rm -r ~/.acme.sh

签发 SSL 证书 使用 HTTP 验证

前提: 域名绑定到了当前服务器的公网 IP 地址

使用 Standalone 模式, acme.sh 自动建立服务器来完成签发, 需要临时占用 80 或 443 端口(需要 root 权限, 所以上面需要切换 root 用户)

# HTTP
acme.sh --issue -d example.com --standalone -k ec-256
# 或者使用 TLS
acme.sh --issue -d example.com --alpn --standalone -k ec-256

这里使用了 ec-256 秘钥, 性能比 rsa-4096 更好

可以指定多个子域名

acme.sh --issue -d example.com -d www.example.com --standalone -k ec-256

使用 DNS 手动验证
acme.sh --issue --dns -d example.com

得到以下输出:

Add the following txt record:
Domain:_acme-challenge.example.com
Txt value:9ihDbjYfTExAYeDs4DBUeuTo18KBzwvTEjUnSwd32-c

Add the following txt record:
Domain:_acme-challenge.www.example.com
Txt value:9ihDbjxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please add those txt records to the domains. Waiting for the dns to take effect.

紧接着手动添加一条 TXT 的 DNS 记录


安装证书 移动至别处
acme.sh --installcert -d example.com --fullchainpath /home/admin/example.crt --keypath /home/admin/example.key --ecc
安装到 Apache/Nginx

Apache

acme.sh --install-cert -d example.com 
--cert-file      /path/to/certfile/in/apache/cert.pem  
--key-file       /path/to/keyfile/in/apache/key.pem  
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem 
--reloadcmd     "service apache2 force-reload"

Nginx

acme.sh --install-cert -d example.com 
--key-file       /path/to/keyfile/in/nginx/key.pem  
--fullchain-file /path/to/fullchain/nginx/cert.pem 
--reloadcmd     "service nginx force-reload"

更新证书

默认会自动更新证书, 也可以手动强制更新证书

acme.sh --renew -d example.com --force --ecc

上文的 ec-256 属于 ECC 证书, 此处添加了 --ecc 选项

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/870571.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号