Powering off Via SSH and Home Assistant

IPv4/6, Port, VPN, proxy, SSH, remote access and more.
Locked
User avatar
colin
Posts: 3
Joined: 26 Jan 2022, 12:23

Powering off Via SSH and Home Assistant

Post 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
User avatar
TM-Allen
TerraMaster Team
Posts: 18
Joined: 05 Jan 2022, 16:18

Re: Powering off Via SSH and Home Assistant

Post 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?
To contact our team, please send email to following addresses, remember to replace (at) with @
Technical team: support(at)terra-master.com (for technical support)
Service team: service(at)terra-master.com (for purchasing, return, replacement, RMA service)
User avatar
colin
Posts: 3
Joined: 26 Jan 2022, 12:23

Re: Powering off Via SSH and Home Assistant

Post 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
User avatar
TMRyan
TerraMaster Team
Posts: 817
Joined: 01 Dec 2020, 11:50

Re: Powering off Via SSH and Home Assistant

Post 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.
To contact our team, please send email to following addresses, remember to replace (at) with @
Technical team: support(at)terra-master.com (for technical support)
Service team: service(at)terra-master.com (for purchasing, return, replacement)
User avatar
titanrx8
Posts: 222
Joined: 17 Jul 2020, 06:17

Re: Powering off Via SSH and Home Assistant

Post 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.
User avatar
colin
Posts: 3
Joined: 26 Jan 2022, 12:23

Re: Powering off Via SSH and Home Assistant

Post 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
User avatar
bgehret
Posts: 1
Joined: 03 Mar 2022, 03:45

Re: Powering off Via SSH and Home Assistant

Post 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!
Locked