什麼時候會用到 acme.sh
我的服務基本上決定不開放,所以沒有辦法符合 certbot 的 requirements ,沒有開防火牆、沒有 port 80 的狀況,所以這時候可以用 acme.sh 來達成 dns-01 的方式取得憑證,並設定好相關服務、自動更新憑證等措施,以下紀錄作法:
install
acme.sh github 在這邊,可以參考相關的指令用法。
最簡單的安裝方式:
curl https://get.acme.sh | sh -s email=tlinuxXXXXXX@gmail.com
安裝好之後要讓路徑生效,可以重新登入,或是直接 reload bashrc
source ~/.bashrc
透過 acme.sh 以 dns-01 取得憑證
以下步驟建議用root可以適當避免一些麻煩,畢竟需要重新啟動服務,讀寫一些設定檔,建議直接用 root 而不是sudo。
需要先準備 name.com 的 api token,可以再 這邊 找到設定方式。
acme 部份如下
sudo su
export Namecom_Username='USERNAME'
export Namecom_Token='TOKEN'
acme.sh --issue -d www.libthomas.org --dns dns_namecom --reloadcmd "/etc/init.d/apache2 reload"
acme.sh --issue -d imap.libthomas.org --dns dns_namecom --reloadcmd "/etc/init.d/dovecot restart"
順利完成之後,再沒有特別指定 install 路徑時,cert 相關檔案會在 /root/acme.sh/xxx_ecc/ 裏面。
update configuration
我有 web/apache2 與 imap/dovecot 兩個服務,分別修改下設定檔,再重新啟動服務來套用到新的路徑。
web/apache2
/etc/apache2/sites-enabled/default-ssl.conf
SSLCertificateFile /root/.acme.sh/www.libthomas.org_ecc/www.libthomas.org.cer
SSLCertificateKeyFile /root/.acme.sh/www.libthomas.org_ecc/www.libthomas.org.key
SSLCertificateChainFile /root/.acme.sh/www.libthomas.org_ecc/ca.cer
imap/docecot
/etc/dovecot/conf.d/10-ssl.conf
ssl_cert = </root/.acme.sh/imap.libthomas.org_ecc/imap.libthomas.org.cer
ssl_key = </root/.acme.sh/imap.libthomas.org_ecc/imap.libthomas.org.key
restart or reload service
/etc/init.d/apache2 reload
/etc/init.d/dovecot restart
renew and notify
acme.sh 會自動把 renew 放到 user crontab 裡
crontab -l
46 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
另外也提供 notify 機制,我的主機可以寄信,就直接用mail
export MAIL_TO="tlinuxxxxxx@gmail.com"
acme.sh --set-notify --notify-hook mail
check
可以看目前憑證
acme.sh list
Main_Domain KeyLength SAN_Domains CA Created Renew
imap.libthomas.org "ec-256" no ZeroSSL.com 2023-07-27T15:17:57Z 2023-09-24T15:17:57Z
www.libthomas.org "ec-256" no ZeroSSL.com 2023-07-27T15:08:26Z 2023-09-24T15:08:26Z