免费SSL申请和自动更新

当前是在mac下操作

安装certbot

bash 复制代码
# mac下brew安装即可
brew install certbot

申请泛解析证书

bash 复制代码
sudo certbot certonly --manual --preferred-challenges=dns -d  '*.yourdomain.com'

## 输出
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for *.yourdomain.com

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

_asdfase.yourdomain.com.

with the following value:
## TXT解析值
有朋自远发来 不亦乐乎

## 此处提示注意验证是否已经在域名服务商配置了TXT解析
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/txt.yourdomain.com.
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

## 如果多次验证失败 可能有技能冷却时间 文档说是1小时

An unexpected error occurred:
Error creating new order :: too many failed authorizations recently: see https://letsencrypt.org/docs/failed-validation-limit/

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/youdomain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/yourdomain.com/privkey.pem
This certificate expires on 2024-04-22.
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

验证证书是否有效

查看证书

bash 复制代码
sudo certbot certificates

## 输出

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: yourdomain.como
    Serial Number: asdfasfasfasdfas
    Key Type: ECDSA
    Domains: *.yourdomain.com
    Expiry Date: 2024-04-22 09:45:32+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/yourdomain.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/yourdomain.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

默认3个月有效期

设置自动续期脚本

bash 复制代码
echo "0 0,12 * * * root $(command -v python3) -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo $(command -v certbot) renew - q"| sudo tee -a /etc/crontab > /dev/null
  • 命令比较简单 用chatgpt做下命令拆解注释

    复制代码
      这是一个shell命令,用于在Linux系统中将Certbot自动续订证书的命令添加到crontab中。
    
      具体分析如下:
      
      echo命令用于输出内容到标准输出。
      0 0,12 * * *部分是cron时间格式,指定了脚本运行的频率。这里表示在每天的0点和12点运行。
      
      root表示以root用户身份运行脚本。
      
      $(command -v python3)是用于获取Python3可执行文件的路径,并将其插入命令中。
      
      -c 'import random; import time; time.sleep(random.random() * 3600)'是通过Python代码实现延迟执行。这段代码会通过import random导入random模块,然后使用import time; time.sleep(random.random() * 3600)来随机延时一定时间,以避免多个服务器同时请求续订证书。
      
      sudo $(command -v certbot) renew -q是用于以root用户身份运行certbot的续订命令。-q参数表示以静默模式运行,输出更少的信息。
      
      sudo tee -a /etc/crontab > /dev/null用于将前面的命令的输出追加到/etc/crontab文件中,并将标准输出重定向到/dev/null来忽略输出。这样,命令的输出信息将不会显示在终端上。
      
      整个命令使用管道符(|)将输出传递给sudo tee命令,并将其添加到/etc/crontab文件中。
      
      
      通过执行这个命令,会将自动续订Certbot证书的任务添加到cron作业中,以在每天的0点和12点执行。这样就能够自动续订证书,确保证书在到期前得到更新。
  • 参考博客

https://ganzhixiong.com/p/95b00866/
letsencrypt官网

相关推荐
橘子真甜~28 分钟前
C/C++ Linux网络编程15 - 网络层IP协议
linux·网络·c++·网络协议·tcp/ip·计算机网络·网络层
Allen正心正念20251 小时前
网络编程与通讯协议综合解析
网络
bing_feilong1 小时前
ubuntu中的WIFI与自身热点切换
网络
CodeByV2 小时前
【网络】UDP 协议深度解析:从五元组标识到缓冲区
网络·网络协议·udp
车载测试工程师2 小时前
CAPL学习-AVB交互层-概述
网络协议·tcp/ip·以太网·capl·canoe
虹科网络安全2 小时前
艾体宝洞察 | 利用“隐形字符”的钓鱼邮件:传统防御为何失效,AI安全意识培训如何补上最后一道防线
运维·网络·安全
石像鬼₧魂石3 小时前
Kali Linux 网络端口深度扫描
linux·运维·网络
鲸鱼电台分台4 小时前
工业应用通信协议:IEC104
网络协议
适应规律4 小时前
UNeXt-Stripe网络架构解释
网络
纸带6 小时前
USB通信的状态
网络