Page 1 of 1

Powering off Via SSH and Home Assistant

Posted: 26 Jan 2022, 12:31
by colin
Hello! I'm looking to poweroff my f2-210 via ssh. Step 7 on this page is where I run into trouble https://www.home-assistant.io/integrations/wake_on_lan/ Seems like sudo visudo doesnt work

I'm trying to run a poweroff command without password but I see terramaster has changed root access via ssh.

How should I approch this?

Thanks,
Colin

Re: Powering off Via SSH and Home Assistant

Posted: 28 Jan 2022, 17:56
by TM-Allen
Hello.Our NAS itself supports WOL wake-up, and users do not need to operate behind SSH.Why do you need to SSH into the background to handle WOL functions?

Re: Powering off Via SSH and Home Assistant

Posted: 29 Jan 2022, 00:58
by colin
How would I use wake on lan to shutdown in this application? I'm trying to shutdown the NAS in a offgrid application if battery voltage gets too low.

I would also like to figure out SSH root for other automations

Re: Powering off Via SSH and Home Assistant

Posted: 29 Jan 2022, 16:35
by TMRyan
In the latest TOS, only the user set up when the system is initialized can use the sudo command to switch to root. Other users do not have ssh permissions. Maybe you need to create a normal user and add ssh permissions to the user and then use visudo to add sudo permissions to the user.
After modification, you need to restart the ssh service.
Not sure if it helps you.

Re: Powering off Via SSH and Home Assistant

Posted: 30 Jan 2022, 00:49
by titanrx8
Why not connect your nas to a TOS-supported UPS and then set the UPS to shut down the NAS at a suitable battery percentage.

Re: Powering off Via SSH and Home Assistant

Posted: 31 Jan 2022, 02:55
by colin
A UPS would be a good option but SSH shutdown and other options are much more flexible.

Part of the problem is # sudo visudo says command not found when logged in as root as mentioned above.

I'm just trying to follow the instructions on the link shown but hitting some roadblocks

"On the target, using an account with sudo access (typically your main account), sudo visudo. Add this line last in the file: hass ALL=NOPASSWD:/usr/sbin/pm-suspend, where you replace hass with the name of your user on the target, if different, and /usr/sbin/pm-suspend with the command of your choice, if different."

Any help would be appreciated

Thanks,

Colin

Re: Powering off Via SSH and Home Assistant

Posted: 04 Mar 2022, 03:21
by bgehret
Did you ever get this sorted?
If not, I have some good news, because I got this working on my F4-210. I also wanted to shut my NAS down when on UPS for a certain amount of time.
I followed this tutorial here: https://siytek.com/home-assistant-shell/ to set up the Shell Commands integration and create/copy the keys. I am a newbie to linux/ssh so all this was new to me.

The YAML config I added for the shutdown command is this:

Code: Select all

shell_command:
  shutdown_tnas: echo YOURTNAS_ADMIN_PASSWORD | ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' -p 9222 admin@YOUR_TNAS_IP sudo -S poweroff
You also need to add the wake_on_lan integration if you want to be able to turn it back on:

Code: Select all

wake_on_lan:
And this to create a switch that can turn the TNAS on and off, and also pings it for status:

Code: Select all

Switch:
  - platform: wake_on_lan
    mac: YOUR_TNAS_MAC
    name: TNAS
    host: 192.168.0.11
    turn_off:
      service: shell_command.shutdown_tnas
To make sure it's working and the keys are copied correctly, I highly recommend calling the command in its entirety (including -i and -o options) from the ssh terminal and ensuring it works or seeing the errors if not.

Let me know how it goes!