How I got Asuswrt device tracker working with SSH key files

Hi all, been trying to access my Asus router through SSH with HA. The device was added via UPnP but the sensors it added are not great as seems they they don’t all work.

Now I have added my private key to HA under ssh_key: /config/ssh/asus_private_key copied the private key from the ppk into my ASUS router admin menu.

I always seems to get back an asyncssh.public_key.KeyImportError: Invalid private key error

Anyone has any ideas

My suggestion would be to follow the steps in the original post. It seems to me you need to enter your public key in the Asus, not the private key.

Right started again.

Looks like I have been able to get this setup but can someone confirm how the sensors are suppose to work? My router is a RT-AX58U and as you can see the new sensors, at the top, are not populating correctly. Only one has populated the rest are showing 0 when the UPnP sensors are showing figures?

The connection must be correct to show the 24 connected devices which match my router app. The last update on the sensor was 7 minutes ago and I have since then downloaded 3 movies on Disney+ so would have expected these figures to jump.

Hello, I can’t get it working with Hassio and an Asus router, already tried so many times.
I paste public key in Asuswrt-Merlin and put private key in Hassio , but it keeps showing
load pubkey "/config/ssh/pri2": invalid format error.

I did the chmod 600.
Is there anything else I might be missing?
Thanks very much.

Did you do this?

  1. Download & open PuttyGen.
  2. Generate a public/private key pair. Click menu Conversions > Export OpenSSH key. Save the (private) key file to the hassio /config/ssh folder (you’ll need to create the ssh subfolder yourself). Make sure it has no file extension. E.g. ssh_asus_private_key.
1 Like

Just some feedback to those who will try to enable ASUSWRT with the new UI -

If you get the warning: “Only provide password or SSH key file”
Listen to what it says:
YOU DO NOT NEED TO INPUT YOUR ROUTER’S PASSWORD.

Sincerely,
Someone who spent too long figuring that out.

PS: I was wondering if the UI accepts /config/ssh/ssh_asus_private_key, and it does, that’s not the issue.

Thanks for this great guide. It took a while but now my wife and I have the garage and basement lights turning on when we get home - without using the cloud!

I am new to HA having recently been left in the lurch by Samsung with a v1 Smartthings hub and unable to source a v3 hub in Canada. Still a ways to go but if and when I receive a Z-wave USB stick I will be well on my way. I really appreciate experts like you taking the time to help newbies like me.

Hi all. I did as described in tutorial but repeatedly receiving “unexpected error” in the UI.
It is “permission denied” as in log file, but I am not able to identify what and why :frowning:
Log file:

Logger: homeassistant.components.asuswrt.config_flow
Source: components/asuswrt/config_flow.py:106
Integration: ASUSWRT (documentation, issues)
First occurred: 16:43:33 (6 occurrences)
Last logged: 17:48:37

Unknown error connecting with AsusWrt router at 192.168.1.1
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/asuswrt/config_flow.py", line 106, in _async_check_connection
    await api.connection.async_connect()
  File "/usr/local/lib/python3.9/site-packages/aioasuswrt/connection.py", line 78, in async_connect
    self._client = await asyncssh.connect(self._host, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 6854, in connect
    return await _connect(options, loop, flags, conn_factory,
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 303, in _connect
    await conn.wait_established()
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 2261, in wait_established
    await self._waiter
asyncssh.misc.PermissionDenied: Permission denied

Any advice pls?

Hi,

As I’m running a linux on my computer, I had to use the puttygen tool in command line. I wrote what I did here: https://github.com/jtbgroup/scripts_and_tricks/blob/b48dacf2a94a919e803999f3e68a282a60d1490f/HOWTO_activate_ssh_on_router.md

I run Home Assistant on a RPi 3+ and my router is an Asus ZenWifi.

In a nutshell, the commands are:

sudo apt install putty
puttygen -t rsa -b 4096 -C "RSA key for ASUS ZenWifi" -o asus_zenwifi.ppk
puttygen asus_zenwifi.ppk -O private-openssh -o asus_zenwifi_private
puttygen -L asus_zenwifi.ppk

Then copy the files as mentioned at the top of the post.

1 Like

Followed the instructions to the letter and got it up and running. Thanks @Emphyrio!

1 Like

I cant get it to work… i get error “Invalid private key” in the logs.
I run HA in docker. On synology nas.

I did step 6 thru putty on the file located on my nas like this:

cd /volume3/docker/homeassistant/ssh
chmod 600 ha_asus

Hello Marcus, I only have the information as stated in the starting post. Some people seem to trip over this step in PuttyGen: “Click menu Conversions > Export OpenSSH key”. Other than that, I’m afraid I can’t be of much help to you.

In case someone has the same problem as me, below is the solution.
I generated the my key pairs on a windows machine using puttygen. This is a different machine from the home assistant machine (which is on rpi). I notice in the private key file, at the bottom, there is an entry private-MAC: xxx
I am not sure if this is referring to the mac address of the window machine (which obviously will be different from the rpi.
On the HA integration screen, when i hit ‘submit’ button, i got ‘unknown error’. The log looks like this:

Logger: homeassistant.components.asuswrt.config_flow
Source: components/asuswrt/config_flow.py:106
Integration: ASUSWRT (documentation, issues)
First occurred: 3:57:43 PM (2 occurrences)
Last logged: 3:59:41 PM

Unknown error connecting with AsusWrt router at 192.168.1.1
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/asuswrt/config_flow.py", line 106, in _async_check_connection
    await api.connection.async_connect()
  File "/usr/local/lib/python3.9/site-packages/aioasuswrt/connection.py", line 78, in async_connect
    self._client = await asyncssh.connect(self._host, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 6887, in connect
    options = SSHClientConnectionOptions(options, config=config, host=host,
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 5596, in __init__
    super().__init__(options=options, last_config=last_config, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/misc.py", line 271, in __init__
    self.prepare(**self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/connection.py", line 6329, in prepare
    self.client_keys = load_keypairs(client_keys, passphrase,
  File "/usr/local/lib/python3.9/site-packages/asyncssh/public_key.py", line 3152, in load_keypairs
    key, certs = read_private_key_and_certs(key, passphrase)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/public_key.py", line 2969, in read_private_key_and_certs
    key, cert = import_private_key_and_certs(read_file(filename), passphrase)
  File "/usr/local/lib/python3.9/site-packages/asyncssh/public_key.py", line 2864, in import_private_key_and_certs
    raise KeyImportError('Invalid private key')
asyncssh.public_key.KeyImportError: Invalid private key

My solution is to generate the key pairs directly from HA via SSH.
In command line, use ssh-keygen

[core-ssh ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /config/ssh/lara_private_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /config/ssh/lara_private_key
Your public key has been saved in /config/ssh/lara_private_key.pub
The key fingerprint is:
SHA256:BLAHBLAHsdfasfdjfS/VgfQCZSA root@core-ssh
The key's randomart image is:
+---[RSA 3072]----+
|      E oo+      |
|     .              |
|    o        o    |
|   . o             |
|    . .oS = + .  |
|     . oo=   . . |
|    . +oB.= . o  |
|     ..X=X= +   |
|      BLAH      |
+----[SHA256]-----+

and like they say, the rest is history

2 Likes

Is there anyone know is this Asuswrt support only Merlin firmware or original Asus firmware also support?
I’m using Rog AX11000 and suppor to enable SSH.

Not really sure, but I think it should work with Asus firmware as well. Just give it a shot!

I am somehow connected, at least it shows me how many devices are connected on my Asus Router, using the latest wrt merlin FW. But…that’s it. No other informations are visible.
I also don’t really understand point 6, chmod 600. Can anyone elaborate this step ?
Thanks

This write-up is many years old now, a lot of things have changed in Home Assistant. The chmod 600, I took that from some general SSH documentation. This was a requirement that was not documented on the AsusWRT HA documentation page.

This worked for me on my TrueNAS Scale, thank you! The new private key didn’t work on my windows computer to SSH into my router, but I was able to import the existing private key into PuTTYgen to generate a new private key that does work. Now I still have the best of both worlds (other than the passphrase).

I will also say, in case someone doesn’t know, you can go to your account in HA, then toggle “Advanced Features” to do basically everything within the UI. You can just add the ASUSWRT device and there are text inputs for port and private key file.

In regards to the passphrase, in the error message it looks like their python function that grabs the certificate has a “passphrase” parameter:

File “/usr/local/lib/python3.11/site-packages/asyncssh/public_key.py”, line 3346, in read_private_key_and_certs
key, cert = import_private_key_and_certs(read_file(filename), passphrase,

I’m curious if they are thinking of implementing a passphrase with it as well, which would be very nice for just that much more added security