How to switch of PC that's running HA linux via terminal command

Sorry my fault. Create 1 user, eg. homeassistant or use an existing one and add it to the sudo group and sudoers file. Then use this user for the ssh command. For user homeassistant you would use:

shell_command:
  my_script: 'ssh [email protected] sudo /usr/local/bin/ha_shutdown.sh'

Put the whole thing in quotes as shown above. Then execute the shell_command:

action:
  - service: shell_command.my_script

You could also try:

shell_command:
  my_script: 'ssh [email protected] sudo shutdown -h now'

no shell script file needed any longer

sadly still no luck

still error 255

what is strange is that “” does not exist, there is nothing in the usr/src folder

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:122
Integration: Shell Command (documentation, issues)
First occurred: 13:47:45 (1 occurrences)
Last logged: 13:47:45

Error running command: ssh [email protected] sudo shutdown -h now, return code: 255

NoneType: None

So it seems that the host is not accepting the ssh connection. Can you please enable debugging for shell_command in configuration.yaml, restart HA, try again and check the logs.

logger:
  default: critical #or whatever you use
  logs:
    homeassistant.components.shell_command: debug

Does Debian 12 only accept ssh connections that use certificates?

Just found this and it includes a solution for your problem:
https://community.home-assistant.io/t/remote-ssh-command-error-255/187891

Hmmm, reading…

did a sudo systemctl status ssh

I get an
Accepted password for trevor from 192…
but
Failed password for homeassistant from 192…

getting closer :frowning:

So what if you replace user homeassistant with user trevor in the shell_command and sudoers file etc?

same error :frowning:

So I believ we are back to certificates- Please read the community discussion above.

Thanks

I’m throwing in the towel here, I tried but doubt that it was correct to generate id_rsa & idrsa.pub files

Added them where I think was correct, but HA is a different setup depending on the Linux OS and the PC setups, so nothing is clear

And still can’t get it to work

I’m giving it up as an échec as I see many others have through out the forums

Its a great shame, either I’m to stupid or HA is too ‘over’ complicated, probably both

Thanks a lot for trying to help me on this
Trevor

Don’t give up to early. Please give another, maybe final try. I’ll provide you with instructions asap.

your to kind

here’s what I did

mkdir -p $HOME/.ssh
chmod 0700 $HOME/.ssh
ssh-keygen -t rsa

In the new /home/trevor/.ssl folder I copied the contents of the id_rsa.pub onto the authorized_keys file

Then added to /usr/share/hassio/ssl (the ssl folder existed already)
both the id_rsa.pub & id_rsa files as not sure which one goes where

rebooted everything

Now I get a error 2 and no longer an error 225
Error running command: ssh -i /usr/share/hassio/ssh/id_rsa ssh [email protected] sudo shutdown -h now', return code: 2

If I now run the
sudo systemctl status ssh

I no longer get the
Failed password for homeassistant from 192…

Follow this. The process is to generate the keys within the HA docker container and then copy them to the host into the correct directory. I hope I didn’t miss anthing. My system is different so I cannot try every step myself. But this should work because I used it sometime in the past.

1.	Create user homeassistant if not already done
2.	Add homeassistant to sudo group: $ sudo usermod -aG sudo homeassistant
3.	Modify the host sudoers file to allow the homeassistant user to skip typing the password when connecting via ssh and running sudo. 
$ sudo visudo
Add the following 2 lines to the user privilege section:
   homeassistant ALL=(ALL) NOPASSWD:ALL
   %sudo ALL=(ALL) NOPASSWD:ALL
4. Save the file.
5. Login to the home-assistant container  (note: home-assistant is the container name. check if your container has the same name or change it in the following command. Check with “docker ps” command for the right name.
$ sudo docker exec -it home-assistant /bin/bash
So now you are logged into the HA OS. Note you could also install the Advanced SSH & Web Terminal add-on instead, open a terminal and execute the following steps. But this is faster, no add-on needed.
6. Generate sshkey
$ ssh-keygen -t rsa (press enter, enter, enter)
7. Copy the sshkey to your host
$ ssh-copy-id [email protected] (type password when prompted)

8. Test ssh connection with sudo: 
ssh [email protected]
Hopefully you are now logged into the host OS. Please say yes!

If this works then your shell_command should also work.

Seems like shutting the device down that runs your HA server would be the last thing anyone would want to do. Have all additional cooling/ventilation efforts failed? If you remotely shut it down when it’s overheating, how do you turn it back on? manually? You cant send a similar command to turn it on obviously.

I did that with a smart plug that I could turn on/off outside of HA.

That is what WOL is for.

It helped me one or twice when my HA system crashed for whatever reason.

Hi

Same as
starob

1m

I did that with a smart plug that I could turn on/off outside of HA.

I do that with a non zigbee device, smart plug running Tuya, so when cooler I can reboot the PC from a distance

gotcha. It might be time to use different hardware my friend. This would drive me nuts if i had this problem.