ホームページ制作/SEO対策なら株式会社サイバーブレーンへ

 03-6275-2667 平日10:00~19:00

 2018-02-09

【超簡単】Let's Encryptで無料のSSL証明書を導入する方法

2016年にサービスが開始されたLet's Encryptは、無料でSSL証明書を発行してくれる素晴らしい認証局です。サービス開始から気になってはいたものの、クライアント案件では有料のものを利用することが多く、今になってようやく発行する機会があったので、発行方法を超簡単に説明したいと思います。コマンドオプションによって色々な方法でインストールが可能ですが、今回は一番シンプルな方法で説明します。

certbot-autoクライアントの取得

まずはcertbot-autoクライアントをダウンロードして、パスが通っているディレクトリに配置します。

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
mv ./certbot-auto /usr/local/bin

必要ツールのダウンロードと証明書の発行

下記コマンドを実行すると、必要なツールのダウンロードが始まり、その後、証明書の発行手続きに入ります。

certbot-auto
もしくは
certbot-auto --debug

発行手続きの詳細

Requesting to rerun /usr/local/bin/certbot-auto with root privileges...
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): メールアドレスを入力してEnter
-------------------------------------------------------------------------------
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を入力してEnter

↑要するに、規約に同意しますか、ということですね。

-------------------------------------------------------------------------------
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

↑単にSSL証明書を利用するだけならnを選択します。

Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: ホスト名
-------------------------------------------------------------------------------
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1を入力してEnter

↑きっと、HTTPS化したいサイトのホスト名が表示されていると思いますので、該当する番号を選択します。

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ホスト名
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/vh-le-ssl.conf
Enabling NameVirtualHosts on *:443
Deploying Certificate for ホスト名 to VirtualHost /etc/httpd/conf.d/vh-le-ssl.conf

↑新しい証明書の発行手続きに入り、/etc/httpd/conf.d/vh-le-ssl.confが自動的に作成されます。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

↑要するに、HTTPへのアクセスをHTTPSにリダイレクトしますか、ということですね。リダイレクト設定は自分ですべきなので、1を選択します。

-------------------------------------------------------------------------------
Congratulations! You have successfully enabled https://ホスト名

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ホスト名
-------------------------------------------------------------------------------

↑これだけで証明書の発行も設定も完了です。httpsでご自分のサイトへアクセスしてみてください。

証明書の場所など

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/ホスト名/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/ホスト名/privkey.pem
   Your cert will expire on 2018-04-25. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. 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
```

↑要するに、証明書は/etc/letsencrypt/live/ホスト名/配下にあって、有効期限は2018-04-25ですよと言ってますね。

証明書の更新方法

certbot-auto renew

なんと、上記コマンドを実行するだけです。手動で実行してもcronで自動実行しても良いのですが、頻繁に実行すると怒られますので、ひと月に1回ぐらいが良いのでしょうか。

~この記事の著者~

セキュリティ対策に関するご相談はこちら

 03-5961-5681 平日10:00~19:00

メールフォーム

あなたが
サイトに
求める要素
あなたがサイトに求める0要素