Synology NAS - SSH Shutdown issue

Hi guys,
I can’t shutdown my Synology from Hassio GUI (HA 0.89.1).
My shell_command is:
turn_off_nas: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] '/sbin/shutdown -h now'

The command works fine in Terminal (SSH access without password on Synology NAS), but not from the switch.
I get this error:

Error running command:
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] '/sbin/shutdown -h now', return code: 255 NoneType: None

I tried also to add this line at the bottom of the nas sudoers file:
admin ALL=(ALL:ALL) NOPASSWD: /sbin/shutdown

but nothing…
Help please?

1 Like

Why don’t you use a command?
Hassio ho shutdown ?

You won’t get access to the host with regular commands (mostly anyway)

Hi, thanks.
Ok, I found
but I’m confused…
How can I use this command to shutdown my Synology NAS? Hassio runs on Rpi.

Ah I misread it… for some reason I thought was running on your NAS.

Ok, don’t worry :wink:
The strange thing is that I was able to shutdown my Nas wis Hassbian, but not with Hassio.

The problem is with Hassio you don’t get access to a lot of functions outside the container… hassbian doesn’t care as it’s a full Linux district with full Linux… just doesn’t give you this…

The other week I was trying to run a bash script to delete email from my Gmail - couldn’t do it. I then found a Python script and it works… Maybe look on Google and see if you can find an alternate script that does the same thing…

I tried to avoid this with a python script, but I can’t execute it… “python3 command not found”
I need to install python on Hassio???

I just used Python… I’ll need to check that tomorrow and let you know…

This was the shell command I created that works.

# Clear Out Gmail Alarm Notifications
  removealarm: python /config/

I then have a button card in lovelace I can use to call it.

No python command for me.

core-ssh:~# python /config/script/                               -bash: python: command not found
core-ssh:~# python3 /config/script/                              -bash: python3: command not found

If I try to execute my

  turn_off_nas: python3 /config/script/

I get this error:
Error running command: python3 /config/script/, return code: 1 NoneType: None

Same issue with python instead of python3…

The right way to install python on Hassio?

I tried also with python_scripts:

but if I execute my script (

import subprocess
import sys
cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'sudo /sbin/shutdown -h now'"
x = subprocess.check_output(cmd, shell=True)

I get this error:

Error executing script: __import__ not found
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/python_script/", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "", line 1, in <module>
ImportError: __import__ not found

Solved following this guide:

Could you tell us, how you did it?
I try to find the guide, but the link is broken.
Thank you


Please could you share with us the shell command that you use inside the

I would like to create the same in order to shutdown my SynologyNass



Can you give us more information? I tried to follow the guide that you reference

Problem for me is that i not able to connect SSH over port 22222 to the RaspberryPI host.
I follow the procedure to import the authorized_keys via USB but all the time i get the same problem
Conection Refused!!!

For me that´s means that the Raspeberry host not allow SSH conection over this port!
:frowning: I just spend hours to implement but no clear information or idea about what is the missing point here…

import imaplib
box = imaplib.IMAP4_SSL('', 993)
typ, data =, 'ALL')
for num in data[0].split():, '+FLAGS', '\\Deleted')

Thank´s for sharing but this is not valid for me :frowning:
I need something to shutdown my Synology Nass from the HA

Hi, I use a simple ssh shell and sshpass to shutdown my Synology Nas.

#! /bin/bash
sshpass -p "thepassword" ssh -t  [email protected] "echo thepassword | sudo -S poweroff"

Just replace thepassword and user by your own credentials

Are there any prequisites to do on the NAS?
I typed in the command, there were no error messages, but nothing happened with the NAS

NAS Side:

Make sure the SSH service is enabled on your NAS
Control Panel > Terminal & SNMP > Terminal > Enable SSH
Make sure the user you use has admin role

On HA side:
First of all try just a normal SSH session to the NAS from your HA shell.
Most probably you will first be prompted to accept the NAS as a valid host (security fingerprint)
After this fingerprint acceptation the sshpass command should work fine