Help wanted: SSH to remote machine to shutdown remote machine

SSH from command line of Hassio works fine. I have set up all keys and I can SSH from HASSIO to my FreeNAS box.

The following command works from hassio to shutdown FreeNAS (using private key)

/usr/bin/ssh -i /root/.ssh/priv-openssh freenas ‘/sbin/shutdown -p now’

And my switch shows up and no config errors, but turning on the switch, as no effect. My assumptions are that maybe the GUI/HASSIO is running as a different user? I have to say I am a bit confused as some HASSIO builds use docker, others run on other OS, etc. If I run ps -ef I don’t see much running and same with top, so when i ssh in, am i in a container?

I am running Hassio on a raspberry pi. I simply copied the image and used etcher to right it to SD card. I admit to being new to hassio, but not new to scripting, although yaml is new to me.

My switch code:

  • platform: command_line
    switches:
    test_ssh:
    command_off: “/usr/bin/ssh -i /root/.ssh/priv-openssh freenas ‘/sbin/shutdown -p now’”
    friendly_name: Shutdown FreeNAS
1 Like

ok, so i figured out that i am running hassos and that this all inside docker. I still need to figure out how ssh runs and connects to other machines.

EDIT - logs are not showing any errors:

core-ssh:/config# tail -f home-assistant.log | grep ssh
2018-12-07 13:34:34 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1860222896] Received {‘type’: ‘call_service’, ‘domain’: ‘switch’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: ‘switch.test_ssh’}, ‘id’: 15}
2018-12-07 13:34:34 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=switch.test_ssh, service_call_id=2ad0cec039924e9093718200accf57c4>

2018-12-07 13:58:50 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_off, service_data=entity_id=switch.test_ssh, service_call_id=d01c0f2c9ab049989d18f75ab283d40c>
2018-12-07 13:58:50 INFO (SyncWorker_18) [homeassistant.components.switch.command_line] Running command: /usr/bin/ssh -i /config/ssh/andrew-priv-openssh -o StrictHostKeyChecking=no freenas ‘/sbin/shutdown -p now’
2018-12-07 13:58:50 ERROR (SyncWorker_18) [homeassistant.components.switch.command_line] Command failed: /usr/bin/ssh -i /config/ssh/andrew-priv-openssh -o StrictHostKeyChecking=no freenas ‘/sbin/shutdown -p now’

Problem solved… besides having my off and on backwards in my brain and ignoring the error i was seeing, it appears that my final problem was name resolution.

I had put names in the host file on hassio, but apparently they don’t persist across some event, not sure what. But as soon as i figured i could not ssh by name anymore, i tried my switch with an ip address an viola, it works.