「Certbot」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) |
細 Kusanaginoturugi (トーク) による編集を Kusakata による直前の版へ差し戻しました |
||
| 6行目: | 6行目: | ||
公式クライアントは '''Certbot''' という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを {{AUR|acme-tiny}} でインストールすることができます。スクリプトで使用するのに適したクライアントとして {{AUR|simp_le-git}} や {{AUR|letsencrypt-cli}} も存在します。 |
公式クライアントは '''Certbot''' という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを {{AUR|acme-tiny}} でインストールすることができます。スクリプトで使用するのに適したクライアントとして {{AUR|simp_le-git}} や {{AUR|letsencrypt-cli}} も存在します。 |
||
{{Note|以前 ''Let’s Encrypt クライアント''と呼ばれていた公式クライアントは、現在 ''Certbot'' と呼ばれています。}} |
|||
== インストール == |
|||
== Certbot == |
|||
''Certbot'' は公式のリファレンスクライアントです。Python で書かれており、証明書を取得するためのコマンドラインツールを提供します。 |
|||
=== インストール === |
|||
{{Pkg|certbot}} パッケージを[[インストール]]してください。 |
{{Pkg|certbot}} パッケージを[[インストール]]してください。 |
||
| 12行目: | 18行目: | ||
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます: |
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます: |
||
* [[Nginx]] 用の実験的なプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。 |
* [[Nginx]] 用の実験的なプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。 |
||
* [[Apache HTTP Server]] |
* {{Pkg|certbot-apache}} パッケージも存在していますが、[[Apache HTTP Server]] を使っている場合の自動インストールは現在 Debian の派生ディストリビューションでしかサポートされていません。 |
||
== 設定 == |
=== 設定 === |
||
証明を作成・インストールする方法は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。 |
証明を作成・インストールする方法は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。 |
||
=== |
==== 手動 ==== |
||
{{Note| |
|||
* Webroot 方式では、Certbotが検証するために、'''HTTP on port 80''' が必要です。 |
|||
** '''HTTPS on port 443''' を使用してCertbotを検証するには、Webroot('''--webroot''')メソッドの代わりにNginx('''--nginx''')またはApache('''--apache''')プラグインを使用する必要があります。 |
|||
* サーバー名は、対応するDNSの名前と一致する必要があります。 |
|||
* {{ic|http://domain.tld/.well-known}} への読み取りアクセスを許可するには、ホスト上でアクセス権を変更する必要があります。 |
|||
}} |
|||
webroot メソッドを使用する場合、certbotクライアントは検証のために使用される、{{ic|/path/to/domain.tld/html/.well-known/acme-challenge/}} の中でチャレンジ/レスポンス認証が行われます。 |
|||
この使用方法は手動インストールよりも推奨されます。自動的に更新が行なわれ、証明書管理が容易になります。 |
|||
{{Tip|1=以下の [Nginx#Server_blocks|nginx server]] 設定は、初めての証明書を取得するのに役立ちます: |
|||
{{hc|/etc/nginx/servers-available/domain.tld| |
|||
<nowiki> |
|||
server { |
|||
listen 80; |
|||
listen [::]:80; |
|||
server_name domain.tld; |
|||
root /usr/share/nginx/html; |
|||
location / { |
|||
index index.htm index.html; |
|||
} |
|||
# ACME challenge |
|||
location ^~ /.well-known/acme-challenge/ { |
|||
default_type "text/plain"; |
|||
root /var/lib/letsencrypt; |
|||
} |
|||
} |
|||
</nowiki> |
|||
}} |
|||
}} |
|||
==== 証明書を取得する ==== |
|||
{{ic|/var/lib/letsencrypt/}} を公開アクセス可能なパスとして使用して、{{ic|domain.tld}} の証明書を要求します: |
|||
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld''' |
|||
(サブ)ドメインを追加するには、現在のセットアップで使用されているすべての登録済みドメインを含めます: |
|||
# certbot certonly --email '''email@example.com''' --webroot -w '''/var/lib/letsencrypt/''' -d '''domain.tld,sub.domain.tld''' |
|||
現在の証明書を(すべて)更新するには: |
|||
# certbot renew |
|||
変わりのアプローチとして [[#自動更新]] を参照してください。 |
|||
=== 手動 === |
|||
{{Note| |
{{Note| |
||
| 85行目: | 42行目: | ||
{{Note|コマンドを複数回実行すると {{ic|/etc/letsencrypt/live/''your.domain''/}} に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。}} |
{{Note|コマンドを複数回実行すると {{ic|/etc/letsencrypt/live/''your.domain''/}} に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。}} |
||
== |
==== Webroot ==== |
||
webroot の方法では、{{ic|yourdomain.tld/.well-known/acme-challenge/}} でチャレンジ/レスポンス認証が行われます。ウェブサーバーを止めることなく証明書を取得・更新できます: |
|||
# certbot certonly --email ''email@example.com'' --webroot -w ''/path/to/html/'' -d ''your.domain'' |
|||
=== Webサーバーの設定 === |
|||
サーバーの設定で {{ic|/etc/letsencrypt/live/''your.domain''/}} の証明書を使うようにしてください。 |
|||
自動構成にプラグインを使用する代わりに、サーバーのSSLを手動で有効にすることをお勧めします。 |
|||
{{Note|Apache または nginx の場合、{{ic|--webbroot}} ではなく {{ic|--apache}} または {{ic|--nginx}} をそれぞれ使用します。ポート443の代わりにポート80を使用して検証する必要がある場合は {{ic|--webroot}} を使用してください。}} |
|||
{{Tip| |
|||
* Mozillaには、より安全な設定を作成するための [https://mozilla.github.io/server-side-tls/ssl-config-generator/ automated tool] が含まれている便利な [https://wiki.mozilla.org/Security/Server_Side_TLS SSL/TLS article] があります。 |
|||
* [https://cipherli.st Cipherli.st] は、最新のWebサーバーのための強固なSSL実装例とチュートリアルが提供されています。 |
|||
}} |
|||
==== |
===== マルチドメイン ===== |
||
Let's Encrypt の署名付きSSL証明書を使用したサーバー {{ic|domain.tld}} の例: |
|||
複数のドメインあるいはサブドメインを使用する場合、全てのドメインに対して webroot を指定する必要があります。別の webroot を指定しないと、既存の webroot が使われます。 |
|||
{{hc|/etc/nginx/servers-available/domain.tld| |
|||
<nowiki> |
|||
# redirect to https |
|||
server { |
|||
listen 80; |
|||
listen [::]:80; |
|||
server_name domain.tld; |
|||
return 301 https://$host$request_uri; |
|||
} |
|||
{{ic|/.well-known/acme-challenge/}} への http リクエストを全て一つのフォルダ (例: {{ic|/var/lib/letsencrypt}}) にまとめることで、マルチドメインの管理がとても楽になります。nginx ならば、以下のようなファイルを作成: |
|||
server { |
|||
{{hc|/etc/nginx/letsencrypt.conf|<nowiki> |
|||
listen 443 ssl http2; |
|||
location ^~ /.well-known/acme-challenge { |
|||
listen [::]:443 ssl http2; |
|||
alias /var/lib/letsencrypt/.well-known/acme-challenge; |
|||
default_type "text/plain"; |
|||
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; |
|||
try_files $uri =404; |
|||
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem; |
|||
ssl_session_timeout 1d; |
|||
ssl_session_cache shared:SSL:50m; |
|||
ssl_session_tickets off; |
|||
ssl_prefer_server_ciphers on; |
|||
add_header Strict-Transport-Security max-age=15768000; |
|||
ssl_stapling on; |
|||
ssl_stapling_verify on; |
|||
server_name domain.tld; |
|||
.. |
|||
} |
} |
||
</nowiki>}} |
|||
そして証明書を作成したいサイトの server ブロックの中に以下のように記述します: |
|||
# A subdomain uses the same SSL-certifcate: |
|||
{{hc|/etc/nginx/servers/example.com.conf|<nowiki> |
|||
server { |
server { |
||
... |
|||
listen 443 ssl http2; |
|||
listen [::]:443 ssl http2; |
|||
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; |
|||
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; |
|||
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem; |
|||
.. |
|||
server_name sub.domain.tld; |
|||
.. |
|||
} |
|||
include letsencrypt.conf; |
|||
# ACME challenge |
|||
location ^~ /.well-known { |
|||
allow all; |
|||
alias /var/lib/letsencrypt/.well-known/; |
|||
default_type "text/plain"; |
|||
try_files $uri =404; |
|||
} |
|||
</nowiki> |
|||
}} |
|||
=== マルチドメイン === |
|||
Management of can be made easier by mapping all HTTP-requests for {{ic|/.well-known/acme-challenge/}} to a single folder, e.g. {{ic|/var/lib/letsencrypt}}. |
|||
The path has then to be writable for the Let's Encrypt client and the web server (e.g. [[nginx]] or [[Apache]] running as user ''http''): |
|||
# mkdir -p /var/lib/letsencrypt/.well-known |
|||
# chgrp http /var/lib/letsencrypt |
|||
# chmod g+s /var/lib/letsencrypt |
|||
==== nginx ==== |
|||
locationブロックを含むファイルを作成し、これを Serverブロック内に組み込みます: |
|||
{{hc|/etc/nginx/conf.d/letsencrypt.conf| |
|||
<nowiki> |
|||
location ^~ /.well-known { |
|||
allow all; |
|||
alias /var/lib/letsencrypt/.well-known/; |
|||
default_type "text/plain"; |
|||
try_files $uri =404; |
|||
} |
} |
||
</nowiki>}} |
</nowiki>}} |
||
Apache の場合、{{ic|httpd-acme.conf}} ファイルを作成してください: |
|||
サーバー構成の例: |
|||
{{hc|/etc/nginx/servers-available/domain.conf|<nowiki> |
|||
server { |
|||
server_name domain.tld |
|||
.. |
|||
include conf.d/letsencrypt.conf; |
|||
} |
|||
</nowiki>}} |
|||
==== Apache ==== |
|||
{{ic|/etc/httpd/conf/extra/httpd-acme.conf}} ファイルを作成してください: |
|||
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki> |
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki> |
||
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" |
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" |
||
| 192行目: | 82行目: | ||
</Directory> |
</Directory> |
||
</nowiki>}} |
</nowiki>}} |
||
そして {{ic|httpd.conf}} で上記ファイルをインクルードします: |
|||
そして、{{ic|httpd.conf}} で上記ファイルをインクルードします: |
|||
{{hc|/etc/httpd/conf/httpd.conf|<nowiki> |
{{hc|/etc/httpd/conf/httpd.conf|<nowiki> |
||
Include conf/extra/httpd-acme.conf |
Include conf/extra/httpd-acme.conf |
||
</nowiki>}} |
</nowiki>}} |
||
letsencrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります。次のコマンドを実行してください: {{ic|# chgrp http /var/lib/letsencrypt && chmod g+s /var/lib/letsencrypt}}。 |
|||
=== 自動更新 === |
===== 自動更新 ===== |
||
{{ic|certbot certonly}} を実行するとき、Certbot はドメインと webroot ディレクトリを {{ic|/etc/letsencrypt/renewal}} に記録します。次回からは {{ic|certbot renew}} を実行することで証明書を自動更新することができます。 |
|||
==== systemd ==== |
|||
[[systemd]] {{ic|certbot.service}} ファイルを作成します |
|||
====== サービス ====== |
|||
以下の {{ic|.service}} ファイルを作成することで完全に自動化することが可能です: |
|||
{{hc|1=/etc/systemd/system/certbot.service| |
{{hc|1=/etc/systemd/system/certbot.service| |
||
| 212行目: | 103行目: | ||
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}} |
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}} |
||
====== Standalone サービス ====== |
|||
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。{{ic|certbot.service}} ファイルに以下のどちらかの行を追加してください: |
|||
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。 |
|||
'''Nginx''' |
|||
* Apache: {{ic|1=ExecStartPost=/bin/systemctl reload httpd.service}} |
|||
{{hc|1=/etc/systemd/system/certbot.service| |
|||
2=[Unit] |
|||
Description=Let's Encrypt renewal |
|||
[Service] |
|||
{{Note|[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。}} |
|||
Type=oneshot |
|||
ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop nginx.service" --post-hook "/usr/bin/systemctl start nginx.service" --quiet --agree-tos}} |
|||
'''Apache''' |
|||
{{hc|1=/etc/systemd/system/certbot.service| |
|||
2=[Unit] |
|||
Description=Let's Encrypt renewal |
|||
[Service] |
|||
Type=oneshot |
|||
ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop httpd.service" --post-hook "/usr/bin/systemctl start httpd.service" --quiet --agree-tos}} |
|||
====== 自動更新タイマー ====== |
|||
[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。 |
|||
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。 |
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。 |
||
| 226行目: | 135行目: | ||
[Timer] |
[Timer] |
||
OnCalendar= |
OnCalendar=daily |
||
RandomizedDelaySec= |
RandomizedDelaySec=1day |
||
Persistent=true |
Persistent=true |
||
| 235行目: | 144行目: | ||
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。 |
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。 |
||
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。{{ic|certbot.service}} ファイルに以下のどちらかの行を追加してください: |
|||
==== その他のサービス ==== |
|||
* Apache: {{ic|1=ExecStartPost=/bin/systemctl reload httpd.service}} |
|||
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。 |
|||
* nginx: {{ic|1=ExecStartPost=/bin/systemctl reload nginx.service}} |
|||
===== nginx ===== |
|||
{{hc|1=/etc/systemd/system/certbot.service| |
|||
2=[Unit] |
|||
Description=Let's Encrypt renewal |
|||
[Service] |
|||
Type=oneshot |
|||
ExecStart=/usr/bin/certbot renew --post-hook "/usr/bin/systemctl restart nginx.service" --agree-tos}} |
|||
===== Apache ===== |
|||
{{hc|1=/etc/systemd/system/certbot.service| |
|||
2=[Unit] |
|||
Description=Let's Encrypt renewal |
|||
[Service] |
|||
Type=oneshot |
|||
ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop httpd.service" --post-hook "/usr/bin/systemctl start httpd.service" --quiet --agree-tos}} |
|||
== 参照 == |
== 参照 == |
||
* [https://certbot.eff.org/ EFF's Certbot documentation] |
|||
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧] |
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧] |
||
2017年10月14日 (土) 13:32時点における版
Let’s Encrypt はフリーかつ自動化されたオープンな認証局です。ACME プロトコルを利用しています。
公式クライアントは Certbot という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを acme-tinyAUR でインストールすることができます。スクリプトで使用するのに適したクライアントとして simp_le-gitAUR や letsencrypt-cliAUR も存在します。
Certbot
Certbot は公式のリファレンスクライアントです。Python で書かれており、証明書を取得するためのコマンドラインツールを提供します。
インストール
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
- Nginx 用の実験的なプラグインは certbot-nginx パッケージに入っています。
- certbot-apache パッケージも存在していますが、Apache HTTP Server を使っている場合の自動インストールは現在 Debian の派生ディストリビューションでしかサポートされていません。
設定
証明を作成・インストールする方法は Certbot のドキュメント を参照してください。
手動
ウェブサーバーのプラグインが存在しない場合、次のコマンドを使って下さい:
# certbot certonly --manual
DNS の TXT レコードを利用した認証を行う場合、次のコマンドを使って下さい:
# certbot certonly --manual --preferred-challenges dns
上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は /etc/letsencrypt/live/your.domain/ に保存されます。
上記のディレクトリに入っている秘密鍵と証明書を使用するように手動でウェブサーバーを設定します。
/etc/letsencrypt/live/your.domain/ に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。Webroot
webroot の方法では、yourdomain.tld/.well-known/acme-challenge/ でチャレンジ/レスポンス認証が行われます。ウェブサーバーを止めることなく証明書を取得・更新できます:
# certbot certonly --email email@example.com --webroot -w /path/to/html/ -d your.domain
サーバーの設定で /etc/letsencrypt/live/your.domain/ の証明書を使うようにしてください。
--webbroot ではなく --apache または --nginx をそれぞれ使用します。ポート443の代わりにポート80を使用して検証する必要がある場合は --webroot を使用してください。マルチドメイン
複数のドメインあるいはサブドメインを使用する場合、全てのドメインに対して webroot を指定する必要があります。別の webroot を指定しないと、既存の webroot が使われます。
/.well-known/acme-challenge/ への http リクエストを全て一つのフォルダ (例: /var/lib/letsencrypt) にまとめることで、マルチドメインの管理がとても楽になります。nginx ならば、以下のようなファイルを作成:
/etc/nginx/letsencrypt.conf
location ^~ /.well-known/acme-challenge {
alias /var/lib/letsencrypt/.well-known/acme-challenge;
default_type "text/plain";
try_files $uri =404;
}
そして証明書を作成したいサイトの server ブロックの中に以下のように記述します:
/etc/nginx/servers/example.com.conf
server {
...
include letsencrypt.conf;
}
Apache の場合、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>
そして httpd.conf で上記ファイルをインクルードします:
/etc/httpd/conf/httpd.conf
Include conf/extra/httpd-acme.conf
letsencrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります。次のコマンドを実行してください: # 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 --quiet --agree-tos
Standalone サービス
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。
Nginx
/etc/systemd/system/certbot.service
[Unit] Description=Let's Encrypt renewal [Service] Type=oneshot ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop nginx.service" --post-hook "/usr/bin/systemctl start nginx.service" --quiet --agree-tos
Apache
/etc/systemd/system/certbot.service
[Unit] Description=Let's Encrypt renewal [Service] Type=oneshot ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop httpd.service" --post-hook "/usr/bin/systemctl start httpd.service" --quiet --agree-tos
自動更新タイマー
タイマーを追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。
/etc/systemd/system/certbot.timer
[Unit] Description=Daily renewal of Let's Encrypt's certificates [Timer] OnCalendar=daily RandomizedDelaySec=1day Persistent=true [Install] WantedBy=timers.target
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。certbot.service ファイルに以下のどちらかの行を追加してください:
- Apache:
ExecStartPost=/bin/systemctl reload httpd.service - nginx:
ExecStartPost=/bin/systemctl reload nginx.service