{"id":630,"date":"2017-05-26T18:45:43","date_gmt":"2017-05-26T10:45:43","guid":{"rendered":"https:\/\/carlos.aboutmy.info\/blog\/?p=630"},"modified":"2017-07-27T17:37:03","modified_gmt":"2017-07-27T09:37:03","slug":"using-certbot-to-signrenew-the-lets-encrypt-certificate","status":"publish","type":"post","link":"https:\/\/carlos.aboutmy.info\/blog\/?p=630","title":{"rendered":"Using Certbot to sign\/renew the Let&#8217;s Encrypt certificate"},"content":{"rendered":"<p>\u65e9\u524d\u5beb\u4e86\u4e00\u7bc7 knowledge transfer \u6587\u7ae0\uff0c\u8b1b\u89e3\u5982\u4f55\u5f9e Let\u2019s Encrypt \u7c3d TLS cert\uff0c\u73fe\u5728\u540c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u3002<\/p>\n<p><a href=\"https:\/\/certbot.eff.org\/\" target=\"_blank\">Certbot<\/a> is an official tool to renew\/sign the cert issued from <a href=\"https:\/\/letsencrypt.org\/\" target=\"_blank\">Let\u2019s Encrypt<\/a>.<\/p>\n<p>Installation of certbot was painful in the old days, so in the first release, I use its official <a href=\"https:\/\/www.docker.com\/\" target=\"_blank\">Docker<\/a> image to do the job.<\/p>\n<p><code>docker run -it --rm -p 443:443 -p 80:80 \\<br \/>\n-v \"\/etc\/letsencrypt:\/etc\/letsencrypt\" \\<br \/>\n-v \"\/var\/lib\/letsencrypt:\/var\/lib\/letsencrypt\" \\<br \/>\nquay.io\/letsencrypt\/letsencrypt:latest certonly<\/code><\/p>\n<p>Then, you can find the cert and key in <code>\/etc\/letsencrypt\/live\/&lt;domain, e.g. carlos.aboutmy.info&gt;\/<\/code><\/p>\n<p>The drawback of this is, you have to stop <a href=\"https:\/\/nginx.org\/en\/\" target=\"_blank\">NGINX<\/a> during the signing. But days have changed, <a href=\"https:\/\/certbot.eff.org\/docs\/install.html#certbot-auto\" target=\"_blank\">certbot-auto<\/a> provides a fairly easy way to do the same thing.<\/p>\n<p>One big advantages of using certbot-auto instead of Docker is that, you did not need to stop NGINX.<\/p>\n<p><strong>1. Download certbot-auto<\/strong><br \/>\n<code>$ curl -OL https:\/\/dl.eff.org\/certbot-auto<\/code><br \/>\n<code>$ chmod +x .\/certbot-auto<\/code><br \/>\n<code>$ sudo mv .\/certbot-auto \/usr\/local\/bin\/<\/code><\/p>\n<p><strong>2. Use certbot-auto to install certbot<\/strong><br \/>\nCertbot requires Python and Python virtualenv, gcc and some devel packages<\/p>\n<p>For RHEL\/CentOS\/Oracle Linux:<br \/>\n<code>$ sudo yum install python-virtualenv python-pip libffi-devel openssl-devel gcc<\/code><\/p>\n<p>For Debian\/Ubuntu:<br \/>\n<code>sudo apt-get install python-virtualenv python-pip libffi-dev libssl-dev gcc<\/code><\/p>\n<p><code>$ certbot-auto --no-bootstrap<\/code><br \/>\n`&#8211;no-bootstrap` means not to install system package automatically, it\u2019s used to keep system as clean as possible.<\/p>\n<p><strong>3. Use certbot to sign cert<\/strong><br \/>\n<code>$ certbot-auto --nginx certonly<\/code><\/p>\n<p>It will read the NGINX config, and list out the domain you have for selection.<\/p>\n<p>If passed the challenge and verification, the cert and key will be saved to<br \/>\n<code>\/etc\/letsencrypt\/live\/&lt;domain, e.g. carlos.aboutmy.info&gt;\/<\/code><\/p>\n<p>The file inside that directory are symbolic links only, which will point to<br \/>\n<code>\/etc\/letsencrypt\/archive\/&lt;domain, e.g. carlos.aboutmy.info&gt;\/<\/code> and the file are named with numbers (e.g. xxx1.pem) for old backups.<\/p>\n<p>So, in NGINX conf, you just make use the cert and key files in the <code>\/etc\/letsencrypt\/live\/<\/code>, it will auto link to the lastest cert and key.<\/p>\n<p><strong>4. Test and Reload NGINX config<\/strong><br \/>\n<code>$ sudo nginx -t<\/code><br \/>\n<code>$ sudo nginx -s reload<\/code><\/p>\n<p><strong>5. Use certbot to renew cert<\/strong><br \/>\n<code>$ certbot-auto --nginx renew<\/code><\/p>\n<p><strong>6. Auto renewal<\/strong><br \/>\nRun <code>certbot-auto --nginx renew<\/code> every 60 days as recommended by Let\u2019s Encrypt since the cert will expiry every 90 days. <\/p>\n<p><code>$ crontab -e<\/code><br \/>\n<code>0 4 1 1,3,5,7,9,11 * \/usr\/local\/bin\/certbot-auto --nginx renew > \/dev\/null 2>&1<\/code><\/p>\n<p>Remark:<br \/>\nIf you are using CloudFlare, you have to replace <code>--nginx<\/code> with <code>--webroot --webroot-path \"%web root path%\"<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e9\u524d\u5beb\u4e86\u4e00\u7bc7 knowledge transfer \u6587\u7ae0\uff0c\u8b1b\u89e3\u5982\u4f55\u5f9e Let\u2019s Encrypt \u7c3d TLS cert\uff0c\u73fe\u5728\u540c\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u3002 Certbot is an official tool to renew\/sign the cert issued from Let\u2019s Encrypt. Installation of certbot was painful in the old days, so in the first release, I use its official Docker image to do the job. docker run -it &#8211;rm -p 443:443 -p 80:80 \\\u2026 <span class=\"read-more\"><a href=\"https:\/\/carlos.aboutmy.info\/blog\/?p=630\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/630"}],"collection":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=630"}],"version-history":[{"count":22,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":666,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions\/666"}],"wp:attachment":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}