Skip to content

Instantly share code, notes, and snippets.

@Senarin
Last active May 16, 2022 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Senarin/9e7492e8ac3df0420ed1e98af65adb1b to your computer and use it in GitHub Desktop.
Save Senarin/9e7492e8ac3df0420ed1e98af65adb1b to your computer and use it in GitHub Desktop.
시놀로지 DSM용 Let's Encrypt 와일드카드 자동 갱신 스크립트 (커스텀 도메인용) / A script for auto-renewing Let's Encrypt wildcard certificate of custom domains in Synology DSM
#!/bin/bash
ACME_DIR="/path/to/acmesh"
ACMECERT_DIR="/root/.acme.sh"
DOMAIN="your-domain.tld"
SYNO_MAINCERT_DIR=$(cat "/usr/syno/etc/certificate/_archive/DEFAULT")
${ACME_DIR}/acme.sh --set-default-ca --server letsencrypt
${ACME_DIR}/acme.sh --set-default-chain --preferred-chain "ISRG Root X1" --server letsencrypt
${ACME_DIR}/acme.sh --server letsencrypt --renew --dns --force -d ${DOMAIN} -d *.${DOMAIN} --yes-I-know-dns-manual-mode-enough-go-ahead-please
/bin/cp -v ${ACMECERT_DIR}/${DOMAIN}/${DOMAIN}.cer /usr/syno/etc/certificate/_archive/${SYNO_MAINCERT_DIR}/cert.pem
/bin/cp -v ${ACMECERT_DIR}/${DOMAIN}/ca.cer /usr/syno/etc/certificate/_archive/${SYNO_MAINCERT_DIR}/chain.pem
/bin/cp -v ${ACMECERT_DIR}/${DOMAIN}/fullchain.cer /usr/syno/etc/certificate/_archive/${SYNO_MAINCERT_DIR}/fullchain.pem
/bin/cp -v ${ACMECERT_DIR}/${DOMAIN}/${DOMAIN}.key /usr/syno/etc/certificate/_archive/${SYNO_MAINCERT_DIR}/privkey.pem
/usr/syno/bin/synosystemctl reload nginx

사용 방법 (DSM 7)

  • 위 파일을 자신의 환경에 맞게 수정
    • ACME_DIR: acme.sh 파일이 있는 경로 지정
    • ACMECERT_DIR: 인증서 파일이 저장되는 경로 지정 (보통 /root/.acme.sh)
    • DOMAIN: 인증서를 발급받을 도메인 이름 지정
  • DSM에 관리 권한이 있는 계정으로 접속
  • 제어판 > 터미널 및 SNMP에서 SSH 서비스 활성화에 체크 및 저장
  • 관리자 계정으로 NAS의 SSH에 로그인한 뒤 sudo -i 명령어 입력으로 루트 권한 획득 (SSH 로그인 계정 암호 입력 필수)
  • NAS 내 적절한 경로에 위 스크립트 파일을 acme.sh 파일과 함께 복사한 뒤 chmod 명령어로 해당 파일의 실행 권한 부여
  • DSM 내 제어판 > 작업 스케줄러 > 생성 > 예약된 작업 > 사용자 정의 스크립트 메뉴에서 작업 설정 > 실행 명령란에 위 스크립트 파일의 경로 입력 (이때 스크립트를 실행하는 계정은 반드시 root여야 함. 일반 설정 탭에서 설정 가능)

Usage of this script (DSM 7)

  • Edit this script to comply with your environment.
    • ACME_DIR: The directory path where the acme.sh file is located in.
    • ACMECERT_DIR: The directory path where the certificate files are saved (Normally /root/.acme.sh)
    • DOMAIN: Your custom domain name for issuing the certificate.
  • Login to your DSM with an account with admin privilege.
  • Navigate to Control Panel > Terminal & SNMP, then turn on Enable SSH service and click Apply button to save.
  • Login to SSH of the NAS (with account that having admin privilege) and switch to root with sudo -i command. (Enter the password of your account when prompted)
  • Copy the edited script file and acme.sh to desired path within your NAS and grant execute permission to the script file with chmod command.
  • Within your DSM, Navigate to Control Panel > Task Scheduler > Create, and select Scheduled Task > User-defined script and enter the absolute path of script file under the User-defined script area in Task Settings tab. (Make sure that you have selected the root user in General Settings tab to the task will run for)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment