Skip to content

Run any SSH command on remote server from Home Assistant service call

License

Notifications You must be signed in to change notification settings

AlexxIT/SSHCommand

Repository files navigation

SSHCommand for Home Assistant

Run any SSH command on remote server from Home Assistant service call. For example, the command on the main host from the docker container.

Installation

HACS custom repository: AlexxIT/SSHCommand.

Or manually copy ssh_command folder from latest release to /config/custom_components folder.

Configuration

Add integration via Home Assistant UI or configuration.yaml.

Usage

New service ssh_command.exec_command:

script:
  run_on_host:
    alias: Run shell command on host
    sequence:
    - service: ssh_command.exec_command
      data:
        host: 192.168.1.123
        port: 22
        user: pi
        pass: raspberry
        command: ls -la

Advanced usage:

script:
  run_on_host:
    alias: Run shell command on host
    sequence:
    - service: ssh_command.exec_command
      data:
        host: 192.168.1.123              # required hostname
        user: pi                         # required username
        pass: secret                     # optional password
        private_key: /config/ssh/id_rsa  # optional private key filename
        passphrase: secret               # optional private key passphrase
        timeout: 5                       # optional timeout
        command:                         # also support multiple commands
          - touch somefile.tmp
          - ls -la

If you want use secrets or change default values, add them to configuration.yaml:

ssh_command:
  host: 192.168.1.123
  port: 22
  user: pi
  pass: !secret ssh_parssword