{"id":351,"date":"2025-02-06T23:02:29","date_gmt":"2025-02-06T15:02:29","guid":{"rendered":"https:\/\/virtualcardx.com\/?p=351"},"modified":"2026-01-04T13:30:19","modified_gmt":"2026-01-04T05:30:19","slug":"%e4%bd%bf%e7%94%a8certbot%e8%87%aa%e5%8a%a8%e7%94%b3%e8%af%b7%e5%85%8d%e8%b4%b9%e8%af%81%e4%b9%a6","status":"publish","type":"post","link":"https:\/\/virtualcardx.com\/en\/2025\/02\/06\/\u4f7f\u7528certbot\u81ea\u52a8\u7533\u8bf7\u514d\u8d39\u8bc1\u4e66\/","title":{"rendered":"Automatically request free certificates with certbot"},"content":{"rendered":"<figure class=\"wp-block-image size-full\"><img decoding=\"async\" data-src=\"http:\/\/virtualcardx.com\/wp-content\/uploads\/2025\/02\/https.jpg\" alt=\"\" class=\"wp-image-353 lazyload\" title=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\"><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>SSH into the server to run your HTTP site as a user with Sudo privileges. Install system dependencies<\/p>\n\n\n\n<p>For Debian-based distributions (e.g. Debian, Ubuntu ...):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt update\n$ sudo apt install python3 python3-venv libaugeas0 <\/code><\/pre>\n\n\n\n<p>For RPM-based distributions (e.g. Fedora, Centos ...):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo dnf install python3 augeas-libs <\/code><\/pre>\n\n\n\n<p>If you installed any certbot packages using the OS package manager, apt, dnf, or yum, you should remove them before installing the certbot snapshot to ensure that certbot uses that snapshot when running commands, not from the OS installation package manager. The exact command to do this depends on your operating system, but common examples are sudo apt-get remove certbot, sudo dnf remove certbot, or sudo yum remove certbot. Setting up a Python virtual environment<\/p>\n\n\n\n<p>Execute the following instructions on the command line on your computer to set up the virtual environment.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo python3 -m venv \/opt\/certbot\/\n$ sudo \/opt\/certbot\/bin\/pip install -upgrade pip <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install certbot<\/h2>\n\n\n\n<p>Run this command from the command line on your computer to install CERTBOT.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo \/opt\/certbot\/bin\/pip install certbot certbot-nginx <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing the certbot command<\/h2>\n\n\n\n<p>Execute the following command on the command line on your computer to ensure that the certbot command can be run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo ln -s\/opt\/certbot\/bin\/certbot\/usr\/bin\/certbot <\/code><\/pre>\n\n\n\n<p>Select how you want to run certbot<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Either get and install your certificate...<\/h3>\n\n\n\n<p>Run this command to get the certificate and have Certbot automatically edit your NGINX configuration to use it and turn on HTTPS access in one step.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo certbot -nginx <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Or, just get certified<\/h3>\n\n\n\n<p>If you are feeling more conservative and want to make changes to the NGINX configuration manually, run this command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo certbot certonly -nginx <\/pre>\n\n\n\n<p>Setting up auto-renewal<\/p>\n\n\n\n<p>We recommend running the following line, which will add CRON jobs to the default crontab.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"0 0,12 * * * root \/opt\/certbot\/bin\/python -c 'import random; import time; time.sleep(random.random() * 3600)' &amp;&amp; sudo certbot renew -q\" | sudo tee -a \/etc\/crontab &gt; \/dev\/null<\/code><\/pre>\n\n\n\n<p>Confirmation of Certbot work<\/p>\n\n\n\n<p>To make sure your site is set up correctly, go to https:\/\/yourwebsite.com\/ In your browser, look for the lock icon in the URL bar. <\/p>\n\n\n\n<p>Upgrade CERTBOT<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo \/opt\/certbot\/bin\/pip install --upgrade certbot certbot-nginx<\/pre>\n\n\n\n<p>If this step results in an error, run sudo rm -rf \/opt\/certbot and repeat all installation instructions.<\/p>\n\n\n\n<p>If you want to change the email address for domain expiration reminders at a later stage, you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ certbot update_account --email yourname@example.com<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-small-font-size\">Source:<a href=\"https:\/\/certbot.eff.org\/instructions?ws=nginx&amp;os=pip\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/certbot.eff.org\/instructions?ws=nginx&amp;os=pip<\/a><\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>SSH into the server with Sudo privileges using ... <\/p>\n<p class=\"read-more-container\"><a title=\"Automatically request free certificates with certbot\" class=\"read-more button\" href=\"https:\/\/virtualcardx.com\/en\/2025\/02\/06\/\u4f7f\u7528certbot\u81ea\u52a8\u7533\u8bf7\u514d\u8d39\u8bc1\u4e66\/#more-351\" aria-label=\"Read more about Automatically request free certificates with certbot\">Read more<\/a><\/p>","protected":false},"author":1,"featured_media":353,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology-share","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":1,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":1512,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/posts\/351\/revisions\/1512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/media\/353"}],"wp:attachment":[{"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualcardx.com\/en\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}