LoginSignup
30
32

More than 1 year has passed since last update.

Let's Encryptの証明書の取得・設定

Last updated at Posted at 2018-07-12

今回はLet's Encryptの証明書を取得・設定をします。

前回同様の環境です。
〜さくらのVPS 1Gプラン〜
メモリ:1G
CPU:仮想2Core
ストレージ:HDD 100GB
OS:CentOS 7(カスタムOS)

仮として、アカウント名はrootもしくはabc123、ドメインはabc.comとします。

はじめに

Terminalでログインできていることを前提とする。

[root@abc ~]# 

1.Let's Encryptをインストールする

次のコマンドを実行し、Let's Encryptをインストールする。

[root@abc ~]# yum -y install certbot python2-certbot-apache
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-safe: ftp.riken.jp

〜省略〜

  python2-mock.noarch 0:1.0.1-9.el7                                             
  python2-parsedatetime.noarch 0:2.4-5.el7                                      
  python2-pyasn1.noarch 0:0.1.9-7.el7                                           
  python2-pyrfc3339.noarch 0:1.0-2.el7                                          
  python2-requests.noarch 0:2.6.0-0.el7                                         
  python2-six.noarch 0:1.9.0-0.el7                                              

完了しました!
[root@abc ~]# 

2.証明書を取得する

※2018年1月中旬頃から取得方法が変更となった。
※2021年4月現在、取得時の文言が変更となった。(時期不明)
Qiitaの他の記事に書かれている方法など、以前の方法では取得できない。
例として、a1b2c3.abc.comの証明書を取得しようとする。
次のコマンドを実行し、証明書を取得する。

[root@abc ~]# sudo certbot --authenticator standalone --installer apache -d a1b2c3.abc.com --pre-hook "apachectl stop" --post-hook "apachectl start"

初回のみ、管理者のメールアドレスを求められるので入力し、returnキーを押す。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

同じく初回のみ、同意するか聞かれるので"Y"を入力し、returnキーを押す。

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): support@abc.com
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------
(Y)es/(N)o: 

Let's Encryptパートナーにメールアドレスを公開していいか聞かれるので"N"を入力し、returnキーを押す。(公開してもいいなら"Y"を入力する。)

(Y)es/(N)o: : Y

-------------------------------------------------------------------------------
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 our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
-------------------------------------------------------------------------------
(Y)es/(N)o: 

httpsにリダイレクトするか聞かれるので"2"を入力し、returnキーを押す。(リダイレクトしたくないなら"1"を入力する。)

(Y)es/(N)o: N
Running pre-hook command: apachectl stop
Obtaining a new certificate
Resetting dropped connection: acme-v01.api.letsencrypt.org
Performing the following challenges:
http-01 challenge for a1b2c3.abc.com
Waiting for verification...
Cleaning up challenges
Running post-hook command: apachectl start
Created an SSL vhost at /etc/httpd/conf/httpd-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf/httpd-le-ssl.conf
Enabling site /etc/httpd/conf/httpd-le-ssl.conf by adding Include to root configuration

~省略~

完了すると通常の画面に戻る。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/a1b2c3.abc.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/a1b2c3.abc.com/privkey.pem
   Your cert will expire on 2019-10-10. 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"
 - 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@abc ~]# 

ブラウザでhttps://a1b2c3.abc.com でアクセスしてみる。
SSL証明書を表示し、発行元がLet's Encrypt Authority X3であること、証明書が有効であることを確認する。
失敗したら最初からやり直す。

注意
Let's Encryptの証明書は発行枚数が制限されている。
1週間に20枚発行すると翌週の同曜日・同時刻まで発行できない。
→時期は不明だが、1週間に50枚まで発行が可能になった模様。(2019年12月9日訂正)
上限に達している中で発行操作をすると、上限に達している旨のメッセージが表示される。
それどころか、次に発行できるまでの期間がさらに1週間伸びてしまう。
制限解除の前日に取得操作をするとそこから1週間発行できないため、最後に発行できたときから約2週間発行できない状態となる。
現時点で1週間以内に50枚発行したか、また、発行から1週間経過したかをよく確認して操作をしていただきたい。
確認を怠ると永遠と発行ができなくなってしまう恐れがある。

30
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
32