LoginSignup
6
8

More than 5 years have passed since last update.

Raspberry Pi で Certbot を利用する

Last updated at Posted at 2017-06-26

Certbotとは

Certbotは、Let's Encryptが提供する無料SSLを自動で発行・インストール・更新するためのツールです。
詳しくはほかのサイトで確認してください。
ここではRaspberry piで利用するためのメモを残します。

インストール手順

準備

こちらからcertbotをダウンロードできます。

まずは自分の利用しているバージョンにあったものを探します。
プルダウンで利用しているhttpサーバーを選択し、OSを選択します。
自分の場合はDebianです。Debian 7と8があるので、/etc/debian_versionを
確認して自分のものと同じものを選択します。

sudo apt-get install python-certbot-apache -t jessie-backports

というコマンドを実行しろとでますが、そのままやってもエラーでインストールできません。

こちらに書いてある手順をまず実行します。

/etc/apt/sources.list に次の行を追加します。

debian 8の場合: deb http://ftp.debian.org/debian jessie-backports main

sudo apt-get update

実行すると

W: GPG error: http://ftp.debian.org jessie-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010

という警告が出ると思いますが、無視しましょう。

インストール

これで準備が整ったので、上記コマンドを再度実行します。

sudo apt-get install python-certbot-apache -t jessie-backports

After this operation, 10.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

と表示されるのでYと入力します。

WARNING: The following packages cannot be authenticated!
augeas-lenses libaugeas0 python-augeas python-cffi-backend python-configargparse
python-six python-idna python-ipaddress python-pyasn1 python-setuptools
python-pkg-resources python-cryptography python-dnspython python-funcsigs
python-openssl python-pbr python-psutil python-rfc3339 python-mock python-acme
python-certbot certbot python-certbot-apache
Install these packages without verification? [y/N] Y

とまた聞かれるのでYと入力します。

Certbotの実行

簡単な方法は、apacheの設定まで行ってくれます。
ちなみにSSLは現在ではIP一つでも複数のSSLを利用できます。以前は出来ませんでしたが。
ただしApache SNI等の特殊な環境じゃないとだめかもしれません。(apache以外知らない…)

sudo certbot --apache

と実行すると、ホスト名(domainと書かれている)を入力するように表示される。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated) (Enter 'c' to cancel):

ここに自分のホスト名を入力するのですが、DNSに問い合わせてIPが取れるかの確認があるために、
DNSの設定を最初に設定しておく必要があります。なお、CNAME等でも問題ないようです。

取得が出来るとapacheの設定を聞かれます。

We were unable to find a vhost with a ServerName or Address of pi.trackpoint.jp.
Which virtual host would you like to choose?
(note: conf files with multiple vhosts are not yet supported)

1: default-ssl.conf | | HTTPS |
2: 000-default.conf | | | Enabled
3: 000-default-le-ssl.conf | xxxx.xxxxxxxxxx.jp | HTTPS | Enabled
Select the appropriate number [1-3] then enter: 1

ここではdefault-ssl.confに書き込んでいる。

設定はこれで終わりになるので、https://にて自分のホストにアクセスできるかをブラウザで
確認します。apacheの再起動などは必要ない模様。

自動更新

更新も非常に簡単で、コマンドは下記になります。

certbot renew

なお、このコマンドでは取得しているSSL証明書のうち30日以内に期限が切れるものが更新されます。
このコマンド後のapache再起動は不要です。(reloadが2回実行されており、そのうちの一つは更新後に実行されているため)

crondで自動更新

crontabにて月1程度更新チェックするように設定すると全自動でアップデートしてくれるようになります。

certbot renew --quiet

として、出力を無くすことも可能。

/etc/crontabに書く場合は、下記の設定を参考にして下さい。

0 1 1 * * root /usr/bin/certbot renew --quiet

なおこのファイルを編集後にcrondの再起動は不要です。(1分毎に読み込んでいるため)
良くcrondの再起動を書いているブログが見受けられますが間違いです。

確認したい人は/etc/crontabに

* * * * * root date >> /tmp/test.txt

と書いて、

touch /tmp/test.txt

を実行後

tail -f /tmp/test.txt

として監視してみるといいです。

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