安装Letsencrypt创建免费SSL证书

Let’s Encrypt是由Internet安全研究组(ISRG)管理的SSL证书颁发机构。 它利用自动证书管理环境(ACME)自动部署几乎被所有主流浏览器信任的免费SSL证书。
本教程将涵盖以下内容:
安装Letsencrypt ACME客户端。
获取Letsencrypt证书。
需要注意和维护的事项。
关于Let’s Encrypt及其颁发的证书的技术细节。

下载和安装Let’s Encrypt



1.安装git
CentOS

  1. sudo yum install git

Debian / Ubuntu

  1. sudo apt-get install git

2.从官方的GitHub存储库下载Let’s Encrypt。 /opt是第三方软件包的公共安装目录,所以让我们将安装到/opt/letsencrypt:

  1. sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt

3.切换到/opt/letsencrypt目录

  1. cd /opt/letsencrypt

创建SSL证书



Let’s Encrypt使用一系列验证来自动完成域名验证(DV)。 证书颁发机构(CA)通过一些方法来验证计算机域的真实性。 一旦您的服务器验证通过,CA将颁发SSL证书给您。
1.使用–standalone参数运行Let’s Encrypt。 对于需要证书的每个其他域名,请将-d example.com添加到命令的末尾。

  1. sudo -H ./letsencrypt-auto certonly --standalone -d example.com -d www.example.com

注意:
Let’s Encrypt不部署通配符证书。 每个子域都需要自己的证书。
2.指定管理电子邮件地址。 这为了让您能重新获得丢失证书的控制权,并在必要时接收紧急安全通知。 按TAB,然后按ENTER或RETURN保存。
3.同意服务条款。
4.如果一切正常,将出现类似下面的消息。 它的输出意味着Let’s Encrypt已经批准并颁发了您的证书。

IMPORTANT NOTES:
– If you lose your account credentials, you can recover them through
e-mails sent to somebody@example.com.
– Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your
cert will expire on 2016-03-31. To obtain a new version of the
certificate in the future, simply run Let’s Encrypt again.
– Your account credentials have been saved in your Let’s Encrypt
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 Let’s
Encrypt, so making regular backups of this folder is ideal.
– If you like Let’s Encrypt, please consider supporting our work by:

Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

Let’s Encrypt证书目录结构



1.列出/etc/letsencrypt/live目录:

  1. sudo ls /etc/letsencrypt/live

2.在创建SSL证书单节的步骤1中指定的各个域名都有自己的目录。 列出以下任意域名目录:

  1. sudo ls /etc/letsencrypt/live/example.com

输出:
cert.pem
chain.pem
fullchain.pem
privkey.pem
3.每个key(.pem)文件有不同的用途:
cert.pem:唯一的服务器证书。
chain.pem:根和中间证书。
fullchain.pem:服务器,根和中间证书的组合(替代cert.pem和chain.pem)。
privkey.pem:私有密钥(不要与任何人分享这个!)。
Let’s Encrypt从中间证书颁发机构颁发证书。 中间证书已由Identrust交叉签名,确保最终证书与所有主要浏览器之间的兼容性。 有关详细信息,请参阅Let’s Encrypt的官网。
4.显示fullchain.pem的文件状态:

  1. sudo stat /etc/letsencrypt/live/example.com/fullchain.pem

输出:

  1. File: ‘live/example.com/cert.pem’ -> ‘../../archive/example.com/cert1.pem’

注意这个文件指向了一个不同的文件,就像步骤3中列出的四个文件一样。它们是软链接,链接到/etc/letsencrypt/archive目录中的证书文件。
5.如果您忘记续订域名证书,Let’s Encrypt将删除/etc/letsencrypt/live中对应的目录(和软链接)。 但是,目录(和软链接)将保留在/etc/letsencrypt/archive和/etc/letsencrypt/keys目录中,以供需要时查看。

维护


续订SSL证书

1.回到cd /opt/letsencrypt目录

  1. cd /opt/letsencrypt

2.执行您在创建SSL证书的步骤1中使用的命令,添加–renew-by-default参数:

  1. sudo -H ./letsencrypt-auto certonly --standalone --renew-by-default -d example.com -d www.example.com

3.片刻之后,将出现以下内容:
IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your
cert will expire on 2016-03-31. To obtain a new version of the
certificate in the future, simply run Let’s Encrypt again.
– If you like Let’s Encrypt, please consider supporting our work by:

Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

自动续订SSL证书(可选)

我们建议您设置自动更新证书,因为很忘记到期日期,尤其是如果您拥有多个不同的域名。 为了避免此问题,并可以使用cron来自动续订证书。
1.在我们执行下面的命令之前,让我们将其分解,并进行一些修改:

  1. echo '@monthly root /opt/letsencrypt/letsencrypt-auto certonly --standalone --renew-by-default -d example.com -d www.example.com >> /var/log/letsencrypt/letsencrypt-auto-update.log' | sudo tee --append /etc/crontab

@monthly:为了简单起见,此命令将在每月的第一天的午夜执行
root:以root用户身份运行命令
/opt/letsencrypt/letsencrypt-auto certonly -standalone -renew-by-default -d example.com -d www.example.com:letsencrypt-auto更新命令。
»/var/log/letsencrypt/letsencrypt-auto-update.log:将标准输出和标准错误记录到名为letsencrypt-auto-update.log的日志文件
tee -append /etc/crontab:将新的cron作业保存到/etc/crontab文件
2.执行您修改的命令以将cron作业添加到您的服务器。

更新Let’s Encrypt

1.回到/opt/letsencrypt目录

  1. cd /opt/letsencrypt

2.从你上次下载Let’s Encrypt的仓库拉取对Let’s Encrypt所做的任何更改:

  1. sudo git pull
发布于:2019-11-21 10:39:52