How to shutdown a Synology DSM 6 NAS using a script

This article covers how to turn off a Synology NAS running DSM 6 using a Windows command line script.

There are some things in computer science that just shouldn’t be a difficult as they are made to be.Basic device functionality should be at the heart of an API design for any appliance. Yet, it is so often the case that manufacturers seemingly set out to impede administrative freedom in the sandboxing of their devices into their own vision.

I have a small Synology device with a couple of 10TB drives in it for use as an overnight backup target. The Synology power management cannot fathom how to spin down the drives and it cannot manage to make itself idle power off, despite the fact that absolutely nothing on the network talks to it via unicast apart from during its backup operation. Thus, in order to use the device as a backup target. It has to be powered on, with its drives spun up, doing nothing all day ahead of its early-hours backup run.

This just isn’t good enough: noise, heat, my power bill, saving the planet. Whatever gets you motivated.

Updating the logic

If the firmware itself cannot do it, then having a backup source do it should be the next best thing. The logical series of steps are:

  1. Backup source prepares to backup
  2. Wake-on-LAN (WoL) packets are sent to the NAS to turn it back on.
  3. The backup source waits for the NAS to boot
  4. The backup job commences
  5. The backup job completes
  6. The source dismounts from the NAS and issues a shutdown command to the NAS
  7. The NAS turns off

Most of the above is fairly easy, apart from 6 and 7, which between Linux command line tools and Synology themselves is just more complicated than they need to be for 2021:

  1. Only root can shutdown the NAS
  2. You can’t log in as root on the NAS
  3. You have to use sudo from an administrative account
  4. You can’t delegate permissions to turn the NAS off to any other account
  5. There is no API function to do it via a command line tool or web-API (which would be the most practical and secure).

If you search on line for how to do this, you will quickly come across the following stop signals:

  • That’s not supported
  • I don’t think you should do that
  • I don’t want you to do that
  • That’s unsafe
  • It’s insecure
  • Why don’t you just use the excellent tools you have available in DSM, I do
  • You don’t need to do that
  • Why?
  • You used to be able to do it in DSM 5, but you can’t for security reasons in DSM 6

… all very helpful. Probably all very valid. Yet for some reason you just want to do what you want to do right? Without the lectures? Shame on you!

How to shutdown a DSM 6 NAS using a script

In the absence of a WebAPI, you will need to use SSH to do this. On Windows I suggest Putty Portable, so at least you aren’t filling the registry on your calling system with things that do not need to be there. You can however use any version of Putty that you prefer or WSL, or a Linux or Mac machine using native tools if you are so inclined.

Download: Putty Portable

Extract plink.exe from the Putty binary bundle. You do not require anything else.


$plinkPath = 'C:\Some Folder\plink.exe'
$nasHostname = 'mynas.mydomain.ext'
$username = 'myusername'
$password = 'mypassword'
$rootPassword = 'rootpassword'
 &"$plinkPath" -batch -ssh -pw $password $username@$nasHostname "echo $rootPassword | sudo -i -S shutdown -h now"


NT Bat File

set plinkPath=C:\Some Folder\plink.exe
set nasHostname=mynas.mydomain.ext
set username=myusername
set password=mypassword
set rootPassword=rootpassword
"%plinkPath%" -batch -ssh -pw %password% %username%@%nasHostname% "echo %rootPassword% | sudo -i -S shutdown -h now"

In summary, after logging-in as an administrative users, the script simply prints the root password into the password challenge from the sudo -i command, which then executes shutdown -n now.

This has been tested as working on DSM 6.3 and DSM 6.4.

Happy misbehaviour!