managed to get this working in the end. For anyone else interested, I gave up with Hass.io. Hassbian has a less complex way of managing users and permissions and the only way the n00b I am could get it to work.
This example relates specifically to turning on and off a HP Microserver via ILO but in principle can be used for any SSH script requiring a private key.
Also not that this assumes you already have the RSA key installed on the server, which I managed to find in a googled tutorial for ILO, and basically requires you to upload one from puttygen.
in this example client_ip = the ILO server IP address
- Install Hassbian OS - https://www.home-assistant.io/docs/installation/hassbian/installation/
- Run first time connected to the network
- Login SSH with pi / raspberry (username / password) with Putty
- Install Samba (see: https://github.com/home-assistant/hassbian-scripts/blob/dev/docs/samba.md)
sudo hassbian-config install samba
- to login to your home assistant account type:
sudo su -s /bin/bash homeassistant
- navigate to /home/homeassistant/.homeassistant
- create a ssh directory using
mkdir .ssh
- open your samba share in windows
\\ipaddress
- navigate to .ssh directory and copy your private key (OpenSSH format) - i.e. privatekey_filename
- Test your script using the format:
ssh -i "/home/homeassistant/.homeassistant/.ssh/privatekey_filename" privatekey_username@client_ip "power off"
where privatekey_username is the username if the key installed to your client - This should test OK.
Then goto configuration.yaml and add:
shell_command:
server_on: ssh -i "/home/homeassistant/.homeassistant/.ssh/privatekey_filename" privatekey_username@client_ip "power on"`
server_off: ssh -i "/home/homeassistant/.homeassistant/.ssh/privatekey_filename" privatekey_username@client_ip "power off"`
In scripts.yaml add:
server_on:
alias: Server ON Script
sequence:
- service: shell_command.server_on
server_off:
alias: Server OFF Script
sequence:
- service: shell_command.server_off
Reboot and this script will show in HA. The same can be done for Server Off.
Enjoy!