0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Certbotで取得したLet's Encryptの証明書を他のサーバに配布する

0
Last updated at Posted at 2026-11-04

複数のサーバで運用している場合、代表の1台のサーバでCertbotで、取得した証明書を、他のサーバに配布する必要があります。
取得した証明書を他のサーバに配布する手法を紹介します。

構成

Cettbot実行サーバ(親 → 各サーバー
※代表のサーバからPushで、各サーバに証明書を配布する

1.証明書受け入れ側(子サーバ)のSSH受け入れ準備(certdeployユーザの作成)

useradd -m -s /bin/bash certdeploy
passwd certdeploy
#パスワードを設定する

install -d -m 700 \
  -o certdeploy -g certdeploy /home/certdeploy/.ssh

install -d -m 700 \
  -o certdeploy -g certdeploy /home/certdeploy/incoming/example.com

2.証明書配布側(親サーバ)でSSH鍵を作成

ssh-keygen -t ed25519 \
  -f /root/.ssh/id_ed25519_certdeploy \
  -C "chimera-certbot-deploy"
#※パスフレーズを聞かれたら、無人応答用なので、何も入力せずEnterキーを押します

#権限設定
chmod 600 /root/.ssh/id_ed25519_certdeploy

公開鍵を証明書受け入れ(子サーバ)に配布する

ssh-copy-id \
  -i /root/.ssh/id_ed25519_certdeploy.pub \
  certdeploy@[子サーバIP or FQDN]

確認する

ssh -i /root/.ssh/id_ed25519_certdeploy \
  -o IdentitiesOnly=yes \
  -o BatchMode=yes \
  certdeploy@[子サーバIP or FQDN] \
  hostname

3.sudo権限の付与(子サーバで実行)

cat > /etc/sudoers.d/certdeploy << EOF
certdeploy ALL=(root) NOPASSWD: /usr/bin/systemctl reload httpd
EOF

3.証明書をコピーテスト(親サーバで実行)

rsync -avL \
  -e "ssh -i /root/.ssh/id_ed25519_certdeploy -o IdentitiesOnly=yes -o BatchMode=yes" \
  /etc/letsencrypt/live/example.com/fullchain.pem \
  /etc/letsencrypt/live/example.com/privkey.pem \
  certdeploy@[子サーバIP or FQDN]:/home/certdeploy/incoming/example.com

4.各種サービスを再起動する(親サーバから実行)

※Apache再起動

ssh -i /root/.ssh/id_ed25519_certdeploy \
  -o BatchMode=yes \
  certdeploy@[子サーバIP or FQDN] \
  "sudo -n /usr/bin/systemctl reload httpd"

これらを、スクリプト化し、証明書取得と合わせてスケジュール実行すれば、証明書も自動更新され、Apacheなどのアプリケーションも再起動含め対応できます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?