Get info from nas using ssh

I want to get info from my nas using ssh on my nas.

Ive got hassio running on a Raspberry Pi.
So i want to logon to my Synology Nas that is running in the same network to get the public ip to check if the VPN on my nas is still working. (Ifconfig | grep tun0)
And want to use the result to send a push message.

I’m new to hassio and spend a while searching this forum, but only find things about ssh on the hassio server.

Can someone help me get started?

1 Like

Have a look here: https://www.home-assistant.io/integrations/shell_command/

I think the shell_command integration can only be used to do something on the OS where Hassio is installed on.

I want to get information from another server. So I need to configure somewhere an IP, Username, Password, the command to execute, or something.
cq create a sensor on that gets information from another network nas using ssh.

Or can this be done with the shell_command?

Theree are ways which you can execute remote commands, but they are beyond my level of skill… mostly it has to do with authentication on the remote machine…

Except you can actually run ssh commands remotely to return data.

Thanks, i’ve done some research, and i think i got it.

I should be able to run a ssh comnand on the host that runs a ssh command on the remote. And indeed, the challenge is the authentication between the host and remote.

You just need SSH keys configured…

okay, got the ssh login without password is working. When I open ssh on Hassio, I now can run the following ssh command:

ssh admin@[ip my nas] ifconfig | grep -i tun0 | awk '{print $1}'

this returns

tun0

Created a sensor:

# nas
- platform: command_line
  name: 'vpn tunnel'
  scan_interval: 300
  command: "ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -q admin@[my nas ip] ifconfig | grep -i tun0 | awk '{print $1}'"

But this does not work. Getting a timeout (looking at the log).

I read somewhere I need some extra in the ssh command (like id_rsa and StrictHostKeyChecking), so tried:

ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -q admin@[my nas ip] ifconfig | grep -i tun0 | awk '{print $1}'

But this does not work.
It works fine on the ssh commandline of my hassio installation (putty and login as root).

The location of the id_rsa file is based on the creation of the ssh keys etc. I used the webpage “http://www.linuxproblem.org/art_9.html” to logon to my nas without a password.

Don’t know what else I can try…

This is why.

Put your id_rsa file inside a directory in the /config directory.

When you SSH in, you are inside another container, and not in Home Assistant container. So running the command from there will work, but when you tell Home Assistant to run the command it’s running inside the Home Assistant container.

Thanks @flamingm0e.

Changed the sensor to:

- platform: command_line
  name: 'vpn tunnel'
  scan_interval: 300
  command: "ssh -i /config/sshnas/id_rsa -o StrictHostKeyChecking=no -q admin@[my nas ip] ifconfig | grep -i tun0 | wc -l"

And it works.
The sensor returns 0 if tun0 not found, and 1 if found.

Where is the /config directory placed on the Pi? Is it just the directory where all the YAML files are located?

Where is the /config directory?
I get a permission denied error when trying to execute a command. What did you do with permissions of the sshnas folder?

How did you get the login without password working? I assume you setup keys? No matter what I try with keys, I get ‘connection refused’. I can login fine if I don’t use keys and just use a password (which I know you shouldn’t do). Any thoughts?