Amazon Linux で certbot(letsencrypt) を使って SSL 証明書を取得する
※2016年5月16日現在の情報です。
バージョンが変わると動作しなくなる可能性があります。
letsencrypt のクライアントが certbot に改名したようです
(See: https://github.com/certbot/certbot)。
Amazon Linux 上で certbot-auto(letsencrypt-auto) を使って SSL 証明書を取得する手順を検証しました。
検証した環境は以下のとおりです。
- certbot-auto(letsencrypt-auto) 0.6.0
- Amazon Linux 2016.03
- amzn-ami-hvm-2016.03.1.x86_64-gp2 (ami-29160d47)
- Nginx 1.8.1
コマンドはすべて ec2-user で実行しました。
試行錯誤した結果、
https://github.com/certbot/certbot/issues/2872#issuecomment-211959637
のように pip と virtualenv のバージョンを上げたらうまくいきました。
pip と virtualenv のバージョンを上げる
sudo easy_install pip sudo pip install --upgrade pip
pip をアップグレードすると、/usr/local/bin/pip
に最新版の pip がインストールされたので、
以降はこちらを使います。
sudo /usr/local/bin/pip install --upgrade virtualenv
letsencrypt 環境を作成
virtualenv で letsencrypt 環境を作成します。
mkdir -p ~/.local/share virtualenv -p /usr/bin/python27 ~/.local/share/letsencrypt . ~/.local/share/letsencrypt/bin/activate
certbot-auto を実行
例では Nginx を使っていますが、Apache や certbot の Standalone Web サーバを使いたい場合は適宜変更してください。
Nginx や Apache を使う場合は予め起動しておいてください。
curl -s -L -O https://dl.eff.org/certbot-auto chmod +x ./certbot-auto ./certbot-auto certonly --webroot -w /usr/share/nginx/html -d your.domain --agree-tos -m your@email.address --debug
以下の様な出力になったら成功です。
yum install の出力 ... Checking for new version... Creating virtual environment... Installing Python packages... Installation succeeded. Requesting root privileges to run certbot... sudo CERTBOT_AUTO=./certbot-auto /home/ec2-user/.local/share/letsencrypt/bin/letsencrypt certonly --webroot -w /usr/share/nginx/html -d your.domain --agree-tos -m your@email.address --debug Version: 1.1-20080819 Version: 1.1-20080819 IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/your.domain/fullchain.pem. Your cert will expire on 2016-08-14. To obtain a new version of the certificate in the future, simply run Certbot again. - If you lose your account credentials, you can recover through e-mails sent to your@email.address. - 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
証明書の更新
以下のコマンドでできるようなので定期的に実行して、Web サーバを reload するようにしておくと自動更新できると思います。
./certbot-auto renew --webroot -w /usr/share/nginx/html --force-renew --debug Checking for new version... Requesting root privileges to run certbot... sudo CERTBOT_AUTO=./certbot-auto /home/ec2-user/.local/share/letsencrypt/bin/letsencrypt renew --webroot -w /usr/share/nginx/html --force-renew --debug ------------------------------------------------------------------------------- Processing /etc/letsencrypt/renewal/your.domain.conf ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- new certificate deployed without reload, fullchain is /etc/letsencrypt/live/your.domain/fullchain.pem ------------------------------------------------------------------------------- Congratulations, all renewals succeeded. The following certs have been renewed: /etc/letsencrypt/live/your.domain/fullchain.pem (success)