【Certbot利用】Let’sEncryptで無料SSL証明書取得のすすめ

【Certbot利用】Let’sEncrypt 無料SSL証明書取得のすすめ

Certbotとは

SSL/TLSで利用する証明書を自動で取得する仕組みのことです。

主にウェブサイトの「http://」を「https://」にすることに使われています。

今回は初級エンジニア向けに、SSL証明書をcertbotを利用して取得する流れを記載しています。

昔はyumからcertbotをインストール出来ていましたが、最近出来なくなってしまったようなので、snapを利用しています。

事前準備

・apache2系の導入が済んでいる
・ドメインを取得している
・メールアドレスを持っている
・CentOS7.6以上のバージョンである。(CentOS9でも動きました)

導入

#epelリポジトリをインストール
yum install epel-release

#snapdパッケージをインストール。
#もしsnapdインストール時にエラーとなってしまうのであれば、CentOSのバージョンが古いです。
yum install snapd

#snapdを有効化
systemctl enable –now snapd.socket

#snapへのシンボリックリンク生成
ln -s /var/lib/snapd/snap /snap

#snapを利用し、certbotをインストール
snap install –classic certbot

#証明書の取得。メールアドレスとドメイン部分は持っているものを利用してください。
certbot certonly –webroot -w /var/www/html -d test.com –email test@gmail.com

#Saving debug log to /var/log/letsencrypt/letsencrypt.log
#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#Please read the Terms of Service at
#https://letsencrypt.org/documents/~~~.pdf. You must
#agree in order to register with the ACME server. Do you agree?
#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#規約への同意 Y を入力し、Enter
(Y)es/(N)o: Y

#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#Would you be willing, once your first certificate is successfully issued, 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 our work encrypting the web,
#EFF news, campaigns, and ways to support digital freedom.
#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#簡単に言うと、キャンペーンやサポート方法、ニュースについてメールしましょうか?です。
#とりあえずSSL導入するだけならば不要なのでN
(Y)es/(N)o: N

#Account registered.
#Requesting a certificate for test.com
#Successfully received certificate.
#Certificate is saved at: /etc/letsencrypt/live/test.com/fullchain.pem
#Key is saved at: /etc/letsencrypt/live/test.com/privkey.pem
#This certificate expires on YYYY-MM-DD.
#These files will be updated when the certificate renews.
#Certbot has set up a scheduled task to automatically renew this certificate in the background.
#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#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
#- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

#上記が表示されれば完成です。

#/etc/httpd/conf.d/ssl.confのSSLCertificateFile、SSLCertificateKeyFile、SSLCertificateChainFileの行を探し、
#下記のように書き換える

SSLCertificateFile /etc/letsencrypt/live/test.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/test.com/chain.pem

#SSLCertificateFileは、サーバ証明書(公開鍵)
#SSLCertificateKeyFileは、中間証明書
#SSLCertificateChainFileは、サーバ証明書と中間証明書の結合ファイルを指します。

#apache再起動
systemctl restart httpd

コメント