利用Certbot申请Let’s Encrypt SSL证书

Let’s Encrypt的证书自然不用多说,大家都知道是一个免费的SSL证书,对于个人及小企业来说,Let’s Encrypt家的证书绝对是够用了。
虽然Let’s Encrypt家的证书是个好东西,但是申请的方式却千差万别,我这里提供一种差异化的申请方式,在Debian、CentOS、Ubuntu系统上能做到无差异的进行部署Let’s Encrypt家的SSL证书。

下载及给certbot赋予可执行权限

首先,选择需要保存certbot文件的目录,可以自定义,也可以选择现有目录,我是选择现有的系统目录,路径是/usr/local/src,先进入保存目录:

cd /usr/local/src

用wget命令下载certbot:

wget https://dl.eff.org/certbot-auto

再赋予可执行权限:

chmod +x certbot-auto

到这里,certbot程序就算安装好了,我们接下来就可以使用certbot程序进行证书申请了。

利用certbot申请Let’s Encrypt证书

利用certbot申请Let’s Encrypt证书需要如下几个条件:
– 系统的root权限
– 443端口未被占用,防火墙放行443端口,且外网能直接访问本机的443端口
– 域名解析到了当前主机
满足以上条件之后,我们就能开始进行Let’s Encrypt证书的申请了。
执行如下命令,我们可在交互程序中进行申请SSL证书:

./certbot-auto certonly

第一次执行的时候,可能会进行一些初始化、安装所必须的依赖等操作,期间可能需要手动确认,待安装完成之后,会要求输入一些所需要的信息,步骤如下:

root@BWH123:/usr/local/src# ./certbot-auto certonly
Bootstrapping dependencies for Debian-based OSes... (you can skip this with --no-bootstrap)
... #略过其中一些系统依赖安装步骤
How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1 #选择认证方式,建议选择1
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): bwh321@live.com #输入想使用的邮箱,用于接收证书到期提醒等信息,建议选择常用的
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A  # 同意TOS,输入A
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: N  # 是否愿意共享邮箱给EFF,我选择了N
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): ssl.bwh123.com  #输入需要申请的域名
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ssl.bwh123.com
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/ssl.bwh123.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/ssl.bwh123.com/privkey.pem
   Your cert will expire on 2018-05-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   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 Certbot so
   making regular backups of this folder is ideal.
 - 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
root@BWH123:/usr/local/src#

可以看到,按照要求输入之后,我们成功申请了Let’s Encrypt的证书,其中证书路径在/etc/letsencrypt/live/ssl.bwh123.com,需要搭配Nginx或者Apache使用的话,直接使用就好了。
证书快到有效期结束时,我们同样也可以使用这个小程序来进行证书有消息更新,更新命令为:

./certbot-auto renew

查看帮助信息可以使用如下命令:

./certbot-auto –help

本命令在VultrBandwagonHostDigitalOceanLinode上的VPS测试通过,搭配Nginx之后可以正常使用,至于SSL证书的情况,可以查看本站的SSL证书,用的就是Let’s Encrypt的证书。
参考信息:https://certbot.eff.org/#pip-other