SOLVED: Remote ON & OFF an ILO server (HP Microserver) with SSH script and key

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

  1. Install Hassbian OS - https://www.home-assistant.io/docs/installation/hassbian/installation/
  2. Run first time connected to the network
  3. Login SSH with pi / raspberry (username / password) with Putty
  4. Install Samba (see: https://github.com/home-assistant/hassbian-scripts/blob/dev/docs/samba.md)
    sudo hassbian-config install samba
  5. to login to your home assistant account type:
    sudo su -s /bin/bash homeassistant
  6. navigate to /home/homeassistant/.homeassistant
  7. create a ssh directory using
    mkdir .ssh
  8. open your samba share in windows
    \\ipaddress
  9. navigate to .ssh directory and copy your private key (OpenSSH format) - i.e. privatekey_filename
  10. 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
  11. 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!

5 Likes