SSH Connection Over Physical USB Cable

Is it possible to SSH to a Balena device using a physical connection (i.e. a USB C cable)?

I can SSH over the network just fine (both using ssh <username>@<local_ip> -p 22222 and balena device ssh <device_uuid> <service_name> but it would be useful to have physical access to the device when deploying/testing it in areas where the wireless network is unreliable.

Before Balena, our device would create a virtual network between the host (i.e. a developer laptop) and the device which would allow the developer to SSH to the device when physically connected. I believe Jetpack did the virtual network setup automatically.

According to our fleet, our device is an Nvidia Jetson Orin NX 16GB in Xavier NX Devkit NVME.

Hey @kyleoptimotive !

Below I’ve pulled in some information for how to directly connect via Ethernet to a device. It requires some NetworkManager setup. We suspect it would work via a USB-C network adaptor as well.

This guide should be helpful if you’d like to make a direct Ethernet connection from a computer to a balena device, without an intermediate router. This setup can be useful for a technician servicing a device onsite. An IP connection can be made to the device using mDNS provided by Avahi. The computer must also run NetworkManager and Avahi.

This setup is accomplished by adding a second, link-local connection. This secondary connection operates at a lower priority than the usual DHCP connection.

On both computers, make these changes:

# we assume connection eth0 exists already
nmcli connection modify eth0 connection.autoconnect-priority 100
# reduce DHCP retries [since NM v1.6]
nmcli connection modify eth0 connection.autoconnect-retries 2
# reduce timeout time for each DHCP probe [since NM v1.2]
nmcli connection modify eth0 ipv4.dhcp-timeout 3 

nmcli connection add type ethernet ifname eth0 con-name eth0-ll
nmcli connection modify eth0-ll connection.autoconnect-priority 50 ipv4.method link-local

You probably don’t need a crossover Ethernet cable for the direct connection. See this article.

You should be able to access the device with its mDNS name, like 395f308.local. mDNS will assign a link local address to both devices, in the block 169.254.0.0/16.

See the nss-mdns repo for more details. See the solution as posted on linuxquestions.org

In Summary

We were able to SSH to our device using an Ethernet cable. We first found the IP address with sudo balena device detect then connected to the device with ssh root@<ip_address> -p 22222.

More Details

I didn’t see the network interface show up on my host PC with ifconfig when I plugged in the Ethernet cable (nor ip a) so I couldn’t use the nmcli commands.

I found the Balena documentation for working in local mode here but local mode didn’t fit our need to have all the features of dashboard (accessing services) while being able to connect locally. We would have also needed to configure our device locally which was not ideal. However, I decided to try out some of the commands from that page in my experimentation.

With the Ethernet cable connected and the device not in local mode, I ran sudo balena device detect to get the IP address that matched the UUID of the Balena device I was trying to access. Then I used ssh root@<ip_address> -p 22222 to access the Host OS service where I was able to access my running containers. I should note that we are using development variants of Balena OS and the behaviour is probably different if using production variants. I have not tested with production variants yet.

Experiment with USB-C

I tried the same steps with the USB-C cable connected but it didn’t work; probably because the USB device needed additional configuration on the Balena device side.

I went down a rabbit hole of configuring the USB device in Host OS on my Balena device. Long story short, I created a script to set up the Balena device as a “USB Gadget” which allowed it to appear as a USB device on my host PC when connected via USB-C cable. Then I had to set up connections on both the host side and the Balena device side.

Eventually I was able to SSH to my Balena device through that set up but it was very tedious and the USB Gadget was reset every time the Balena device was power cycled. Since the whole point of this post is to find a way to access a Balena device in the scenario it can’t access the Cloud, this method isn’t viable.

1 Like