Auto renew SSL certificate with ZeroSSL through acme.sh in Synology
1 Register a ZeroSSL account and generate EAB credentials
Here’s the link to create EAB credentials:
https://app.zerossl.com/developer
2 Create a scheduled task to run a script that auto renew the certificate
2.1 Prepare the script and folder
Create a folder /volume1/docker/acme
Put this script in the folder and name the script file as my_update_ssl.sh.
Note:
- I am using 5001 as HTTPS port for my DSM, you may change it or remove it if you use HTTP instead.
- I also want to deploy the certificate to my router, so in the script I mapped a .ssh directory into the docker so that I can use the SSH key. You may remove that -v “${ACME_VOLUME}/.ssh”:/root/.ssh line and the part of step 5).
|
|
In order to use SSH in the docker (to connect to my router and transfer the certificate key), I have also done these:
Generated a SSH key pair id_rsa_dsm2router without passphrase
Put the SSH private key to the /volume1/docker/acme/.ssh folder
Run the docker as shown in the docker run –rm … script above, then
1
docker exec -it acme.sh sh
then inside the docker’s shell, execute
1
ssh-add ~/.ssh/id_rsa_dsm2router
I also added a config file like this:
1 2 3 4 5
Host router HostName 192.168.1.100 User root Port 10022 IdentityFile ~/.ssh/id_rsa_dsm2router
As shown below, the file structure should be:
For information about SYNO_DID and deploying through HTTPS, check this:
https://github.com/acmesh-official/acme.sh/wiki/Synology-NAS-Guide#deploy-the-default-certificate
For information about deploying certificate through SSH with acme.sh, see:
https://github.com/acmesh-official/acme.sh/wiki/deployhooks#examples-using-ssh-deploy
For uHTTPd web configuration in OpenWrt, see:
https://openwrt.org/docs/guide-user/services/webserver/uhttpd
2.2 Create a scheduled task
Open Control Panel, Task Scheduler, create a new scheduled task/User-defined script.
Name it as acme, run as root.
Schedule it to run Repeat monthly.
On Task Settings, enter this for the User-defined script:
|
|
A note for the meaning:
it run the script, then redirect the output to the log.txt.
That part is written to stderr, use 2> to redirect it. For example:
foo > stdout.txt 2> stderr.txt or if you want in same file:
foo > allout.txt 2>&1
File descriptor 1 is the standard output (
stdout
). File descriptor 2 is the standard error (stderr
).At first,
2>1
may look like a good way to redirectstderr
tostdout
. However, it will actually be interpreted as “redirectstderr
to a file named1
”.
&
indicates that what follows and precedes is a file descriptor, and not a filename. Thus, we use2>&1
. Consider>&
to be a redirect merger operator.
https://stackoverflow.com/questions/818255/what-does-21-mean
https://stackoverflow.com/questions/6674327/redirect-all-output-to-file-in-bash