ずいぶん今更感もありますが、さくらの VPS 環境に Let's Encrypt で発行した証明書を
使ってサイトを SSL 化したときのまとめです。
Let's Encrypt は、認証局(CA)として「SSL/TLSサーバ証明書」を無料で発行するとともに、証明書の発行・インストール・更新のプロセスを自動化することにより、TLS や HTTPS(TLSプロトコルによって提供されるセキュアな接続の上でのHTTP通信)を普及させることを目的としているプロジェクトです。2016年4月12日 に正式サービスが開始されました。出典: Let's Encrypt 総合ポータル
Let's Encrypt 自体はプロジェクトの名称のようですが、ぼくたち利用者にとっては無料で SSL 証明書を発行するためのツールと言ってしまっても過言ではないような、ちょっと乱暴すぎるような気もしなくもないです。
しかしながら、2018年1月からワイルドカード証明書にも対応することが公式サイトで発表されました。
ますます便利になり、来年が待ち遠しいです。笑
$ sudo curl https://dl.eff.org/certbot-auto -o /usr/bin/certbot-auto
$ sudo chmod 700 /usr/bin/cerbot-auto
/usr/bin だけでなく、 /usr/local/bin も sudo 権限が必要のようです。/usr/local/bin にはデフォルトではパスが通っていないので、もし /usr/local/bin に置いた場合はパスを通してやる必要があります。
$ certbot-auto certonly \
> --webroot \
> -w /path/to/webroot \
> -d your-domain.com \
> --email=test@test.comRequesting to rerun /usr/local/bin/certbot-auto with root privileges...
Bootstrapping dependencies for RedHat-based OSes... (you can skip this with --no-bootstrap)
yum is /usr/bin/yum
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: ftp.riken.jp
* extras: ftp.iij.ad.jp
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: ftp.iij.ad.jp
Package augeas-libs-1.0.0-10.el6.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Package redhat-rpm-config-9.0.3-51.el6.centos.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
... 以下略
上記のように、 Webroot のパス、ドメイン名、メールアドレスを指定します。
Install 7 Package(s)
Upgrade 19 Package(s)Total download size: 42 M
Is this ok [y/N]: y
また、オプションは他にも様々あるので
$ cerbot-auto --help
などで参照すると良いと思います。
続いて、規約に同意します。
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.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 <--- Aを入力して同意-------------------------------------------------------------------------------
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 <--- いかなる理由でもメールが来るのは嫌だったので強気の N を指定ww
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for your-domain.com
Using the webroot path /path/to/webroot for all unmatched domains.
Waiting for verification...
Cleaning up challengesIMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/your-domain.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/your-domain.com/privkey.pem
Your cert will expire on 2017-12-30. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto 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
以上で各種証明書の発行が完了しました。
$ sudo ls -l /etc/letsencrypt/live/your-domain.com/
total 4
-rw-r--r-- 1 root root 543 Oct 1 19:07 README
lrwxrwxrwx 1 root root 45 Oct 1 19:07 cert.pem -> ../../archive/your-domain.com/cert1.pem
lrwxrwxrwx 1 root root 46 Oct 1 19:07 chain.pem -> ../../archive/your-domain.com/chain1.pem
lrwxrwxrwx 1 root root 50 Oct 1 19:07 fullchain.pem -> ../../archive/your-domain.com/fullchain1.pem
lrwxrwxrwx 1 root root 48 Oct 1 19:07 privkey.pem -> ../../archive/your-domain.com/privkey1.pem
パスをシンボリックリンクにすることで、スムーズに証明書を更新できる仕組みになっているようです。
証明書の更新は certbot-auto renew するだけ。
管理するすべての証明書が更新されるようです。(シンボリックリンクなので ssl.conf ファイルは変更不要)
もう一度インストール完了後の IMPORTANT NOTES を抜粋
Your cert will expire on 2017-12-30. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
ssl.conf で必要なディレクティブに対応するファイルは以下です。
SSLCertificateFile cert.pem (SSLサーバ証明書ファイル)
SSLCertificateKeyFile privkey.pem (SSLサーバ証明書とペアになる秘密鍵)
SSLCertificateChainFile chain.pem (CSPSSLの中間証明書ファイルを指定)
ssl.conf の例
ぼくの環境だと apache version 2.2 系なので、 /etc/httpd/conf.d/ssl.conf 内に記載します。
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/your-domain.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/your-domain.com/chain.pem
# 諸々省略します…
</VirtualHost>
具体的な方法については以前紹介したのでそちらをご覧ください。
0 1 * * 0 certbot-auto renew --post-hook "/etc/init.d/httpd graceful" >/dev/null 2>&1
mac に pip をインストールする
mac は標準で python が入っていますが、パッケージ管理の pip がインストールされていないので入れてみました。
2017/05/26 09:00
[GAS] Google Drive の特定フォルダ配下のフォルダ・ファイルの権限を一括で移譲する
Google Drive の特定フォルダ配下のファイル・フォルダの権限を一括で移譲するツールを Google Apps Script で作りました。
2018/11/10 15:54
[Windows] Ophcrack を使ってユーザーパスワードを解析する方法
家族で使っていた Windows7 のログインパスワードを忘れたため、Ophcrack を使って解析したときの記録です。
2017/09/30 21:00
[shell] フォルダ内にある大量の ZIP ファイルをまとめて解凍する
とある ZIP を解凍すると中に大量の ZIP が居たときに幸せになれるコマンドを紹介します
2018/06/19 23:45
[MySQL] データファイルから DB を復元する
先日 MySQL が再起動できなくなる問題が発生し、急遽データファイル(.frm, .ibd)から復元しました
2018/11/25 12:44