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

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.

OK, that would be another way. But you can use remote ssh for not only shutting down the host but for any other host command, like restarting processes or other containers etc. So it might still be helpful.

BTW: I think neither. The issues here are coming from the fact that you have a very special use case and that HA is running in a container so it has very limited access to the resources on the host. Because of that we have to used ssh and certificates. So at the end, security is making this more complicated.

Oaky

managed all that can ssh from this pc using ssh 192.168.1.40 (as before) or ssh [email protected]

doesn’t solve the shutdown problem though, though now not sure what I should use in my /config/shell_commands.yaml

Crazy, that I am already, two days on this dopey problem, later I’ll be able to place the small no fan Zotac PC in a normal room that doesn’t get like a sauna

I use smart plugs for many things now, my cable/fiber routeur, base station for my Wyze camera setups, I can boot all of these from may other home, sometimes saving me having to drive 400km just to switch of and back on a plug

OK, I just remembered that you can shutdown the host from within HA. And in fact there is a service called hassio.host_shutdown
So all you need to do is to call this service either from the developer tools or from an automation.
Very simple. :grinning:

1 Like

No ssh, no certificates etc needed!

does that work regardless of the host? I’ve always run mine from a raspberry so never tried it on other configurations.

Just tried that and it WORKS

Just changed the -service to the following, and the PC shuts down

  • service: hassio.host_shutdown

starob
You are the man

Many many thanks for your patience and help
This may be useful to many as I came across many people asking hwo to shut down their PC

Yes it should work. You can simply try develper tools->services search for hassio.host_shutdown and execute it. It will not work if the HA host is also virtalized like on Proxmox etc.