【初心者】「Let’s Encrypt」を使った無料のSSL証明書を発行しhttps化する方法

この記事は 4 分で読めます。
概要

無料のSSL「Let’s Encrypt」自動認証システムを使用して、自身のサーバーをhttpからよりセキュアなhttpsにする方法を紹介します。今回は、Ubuntu 18.04 LTSにてSSL証明書発行時に失敗しないための全プロセスを紹介します。

本記事の読者層

無料でSSHを利用したい方

セキュアな接続をしたい方

最近では、httpよりhttpsのSSL認証されている方がgoogleの評価が高いそうだ。

そうなんだ

目次

「Let’s Encrypt」とは? HTTPからHTTPSへの暗号化

Let’s EncryptとはWEBサイトにTLS証明書を提供する非営利の認証局です。現在、約3億人がこのサービスを利用します。人の介入なしに手続きがすべて自動化されているため、TLS認証を無料で取得できることが特徴です。

TLS (Transport Layer Security) とはSSL (Secure Sockets Layer) の次世代規格です。現在一般的にSSLと呼んでいるのは実質「TLS」を指していることが多いです。どちらも安全に通信をするためのセキュリティプロトコル、すなわち暗号化通信の仕組みです。

WEBサイトのURLの手前に、「http://」「https://」と書かれている表記を目にしたことはあるでしょうか。それぞれHTTP(Hyper Text Transfer Protocol)と、HTTPS(Hypertext Transfer Protocol Secure)と呼ばれ、前者を暗号通信化したものが後者、すなわち「TLSプロトコル」にしたものとなります。

「Let’s Encrypt」により暗号化されていない「http://」を暗号化した「https://」へ自身のコンテンツを移行できます。これにより郵便で言う封書のように中身が受け手以外には分からないようになり、安全に閲覧することができるようになります。

SEO対策では、TLS認証を受けているサイトの方が、上位検索に表示されやすいことが知られています。

下記では、無料でできる「Let’s Encrypt」の設定について解説します。

Let’s Encryptの設定方法

今回は、Linux ディストリビューションのUbuntu 18.04 LTSを利用します。

Linuxのターミナルから、以下のように「certbot」コマンドを入力します。Certbotを一回実行すると、無料のHTTPS証明書を永久に自動的に取得できます。

Cerbotのインストールは以下のようにおこないます。

$ sudo apt-get install certbot python3-certbot-apache

ここでは、すでにドメイン名を取得している物として話を進めていきます。まだ独自ドメインを持っていない場合は以下をご参考にドメイン名を取得ください。

使用バージョンは、Ubuntu18.04 LTS

「XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX」は自身のドメイン名です。

sudo certbot --apache -d XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

メールアドレスを入力して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を入力してEnter

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ホスト名
Waiting for verification...
http-01 challenge for ホスト名
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/000-default-le-ssl.conf
Enabled Apache socache_shmcd module
Enabled Apache ssl module
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

1を選択します。

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

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

これで証明書を獲得できます。

どこかで失敗してしまった場合、

再度「certbot」コマンドをやり直します。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/daraberu.aa0.netvolante.jp.conf)

What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

ここで、「1」を選択

Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Keeping the existing certificate
Deploying Certificate to VirtualHost /etc/apache2/sites-enabled/000-default-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): 2

「2」を入力

Congratulations! You have successfully enabled
https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/privkey.pem
   Your cert will expire on 2022-11-08. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - 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

上記の最初の分のように
「Congralations! You have successfully enabled」(おめでとう、成功しました!)と表示されれば、証明書が発行されたことになります。

 証明書ファイルの保存先

発効が成功すると、すべての証明書ファイルが「/etc/letsencrypt」内に作成されます。

$ls -l /etc/letsencrypt/live/[DOMAIN NAME]

この自身のドメイン名フォルダ「DOMAIN NAME」に以下の4つの生成ファイルができているはずです。

cert.pem
chain.pem
fullchain.pem
privkey.pem

 更新

この自動認証局により得られたSSL 証明書3 か月間のみ発行され、更新する必要があります。

以上です。お疲れ様でした。

まとめ

本記事のポイント

「Let’s Encrypt」で提供されるSSL証明書発効で、HTTPから暗号化通信対応のHTTPSへ移行できる。

「Let’s Encrypt」は専用コマンドである「certbot」コマンドで無料SSL証明を発行してもらえる。

関連リンク

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

コメント

コメントする

目次