Certbot

提供: ArchWiki
2016年6月16日 (木) 14:53時点におけるKusanaginoturugi (トーク | 投稿記録)による版 (日本のwikipediaへのリンクに修正)
ナビゲーションに移動 検索に移動

Let’s EncryptACME プロトコルを利用し、フリーかつ自動化されたオープンな認証局です。

公式クライアントは Certbot と呼ばれており、コマンドラインから有効な SSL 証明書を取得できます。手動で CSR 作成を行うミニマルなクライアントを acme-tinyAUR でインストールすることができます。スクリプトで使用するのに適したクライアントとして simp_le-gitAURletsencrypt-cliAUR も存在します。

ノート: 以前 Let’s Encrypt client と呼ばれていた公式クライアントは、現在 Certbot と呼ばれています。

Certbot

Certbot は公式のリファレンスクライアントです。Python で書かれており、証明書を取得するためのコマンドラインツールを提供します。

インストール

certbot パッケージをインストールしてください。

公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:

  • Nginx 用の実験的なプラグインは certbot-nginx パッケージに入っています。
  • certbot-apache パッケージも存在していますが、Apache HTTP Server を使っている場合の自動インストールは現在 Debian の派生ディストリビューションでしかサポートされていません。

設定

証明を作成・インストールする方法は Certbot のドキュメント を参照してください。

手動

ノート: この方法では、一時的にウェブサーバーを停止する必要があります。#Webroot の方法ではウェブサーバーを実行しながらでも認証が行えます。

ウェブサーバーのプラグインが存在しない場合、次のコマンドを使って下さい:

# certbot certonly --manual

上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は /etc/letsencrypt/live/your.domain/ に保存されます。

上記のディレクトリに入っている秘密鍵と証明書を使用するように手動でウェブサーバーを設定します。

Webroot

webroot を使う場合は、yourdomain.tld/.well-known/acme-challenge/ でチャレンジ/レスポンス認証を行います。ウェブサーバー (例: Apache/nginx) を止めることなく証明書を取得・更新できます。

# certbot certonly --email email@example.com --webroot -w /path/to/html/ -d your.domain

サーバーの設定で /etc/letsencrypt/live/your.domain/ の証明書を使うようにしてください。

Multiple domains

If you use more than one domain or subdomains, the webroot has to be given for every domain. If no new webroot is given, the previous is taken.

Management of this can be made much easier, if you map all http requests for /.well-known/acme-challenge/ to a single folder, e.g. /var/lib/letsencrypt. For nginx you can achieve this by placing this location block within server blocks of sites you want to request certificates for:

location /.well-known/acme-challenge {
    root /var/lib/letsencrypt;
    default_type "text/plain";
    try_files $uri =404;
}

For Apache you can achieve this by creating the file httpd-acme.conf:

/etc/httpd/conf/extra/httpd-acme.conf
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

and including it in httpd.conf:

/etc/httpd/conf/httpd.conf
Include conf/extra/httpd-acme.conf

The chosen path has then to be writable for the chosen letsencrypt client. It also has to be readable by the web server; you can achieve this thereby : chgrp http /var/lib/letsencrypt && chmod g+s /var/lib/letsencrypt.

自動更新

certbot certonly を実行するとき、Certbot はドメインと webroot ディレクトリを /etc/letsencrypt/renewal に記録します。次回からは certbot renew を実行することで証明書を自動更新することができます。

以下の .service ファイルを作成することで完全に自動化することが可能です:

/etc/systemd/system/certbot.service
[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew

タイマーを追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。

それから、タイマーを追加することで毎月証明書を更新できます。

/etc/systemd/system/certbot.timer
[Unit]
Description=Monthly renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=monthly
Persistent=true

[Install]
WantedBy=timers.target

certbot.timer起動有効化してください。また、証明書をいますぐ更新したい場合は certbot.service起動してください。

証明書を更新するたびにウェブサーバーを再起動させることもできます。certbot.service ファイルに以下のどちらかの行を追加してください:

  • Apache: ExecStartPost=/usr/sbin/systemctl restart httpd.service
  • nginx: ExecStartPost=/usr/sbin/systemctl restart nginx.service

参照