How to Shutdown Terramaster NAS with SSH keypair and shell_command

Yes! Seems like login Happened!
But not working yet.
Now I get:

stdout: ""
stderr: "bash: line 1: poweroff: command not found"
returncode: 127

In config.yaml i have:

shell_command:
 shutdown_tnas: ssh -i /config/.ssh/id_ed25519 -o 'StrictHostKeyChecking=no' -p 9222 [email protected] poweroff

Try using the full path, like /sbin/poweroff or something like that… To find where is the command, use ‘which poweroff’ from an interactive ssh session of the NAS.

1 Like

You may also want to SSH from the HA CLI and run ‘whoami’ to make sure it’s logging you in as the correct user.

1 Like

Guys, it worked!
I don’t really know how to thank you for all the help you gave me and patience you showed.
I don’t even really know which reply to mark as solution.
Thanks forever and ever and ever and ever…

P.s.
To be thorough, in case anyone else will ever need this, NAS warned me that “shutdown” should be used instead of “poweroff”

2 Likes

Finally the solution was brought by @FriedCheese and @blackfede. Thanks, you made this a great day.

To summarize:

  1. Install and activate ssh on both HA and NAS.

  2. Access HA cli and generate keys with

ssh-keygen

don’t set passphrase and when prompted for file path:

  1. Type: /config/.ssh/id_rsa.pub

  2. Copy the generated keys to NAS using:
    ssh-copy-id -i /config/.ssh/id_rsa.pub user@NAS_IP using your credentials.

  3. Run:
    chmod 600 /config/.ssh/id_rsa’

  4. Create a shell_command entry in config.yaml:

shell_command:
 shutdown_nas: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' -p 9222 user@NAS_IP /sbin/shutdown

using your credentials.

  1. Restart HA

Now you should be able to call a service called: shutdown_nas

This way, I got rid of the need for a smart UPS.

Please correct me if I badly reported something.
If you encounter an issue, since I mistook almost everything could be mistaken, you’ll likely find the brief solution among replies, so take time to and care of reading.

3 Likes

Woo! I’m glad it worked!

1 Like

Thanks to you and @FriedCheese

1 Like