WSL – SSH into Device When Connected via Hotspot

hotspotnetworkingsshwindows-subsystem-for-linuxwireless-networking

I have connected my Raspberry Pi to Windows computer's hotspot network. I cannot connect the Pi to the Wi-Fi network at my university because they only allow one device at a time (so I'll lose internet on my laptop if I connect the Pi to the WAP).

From PowerShell, if I type ssh npi (npi being the hostname of the Pi), it works as expected. However on WSL (Debian), it just seems to hang/wait for a long time and nothing happens.

How do I connect to my Pi via WSL when it's connected to my computer's hotspot?

Best Answer

Interesting scenario. I'm going to take an educated guess here, since recreating this on my end would be a bit too time consuming. But keep in mind that I haven't had a chance to test this (however, for future readers, the OP has confirmed that it works via comments).

The problem seems to be that:

  • The Windows host has a connection to the Internet through the Wi-fi adapter to your university's network.

  • That connection is shared to WSL2 using a Hyper-V switch (that we really don't have much control over).

  • That connection is also shared (separately) with the RPi through the Windows hotspot feature.

  • As a result, the WSL2 Debian distribution and the RPi are on two separate networks that have no route between them.

If you just need ssh access, then my proposal would be to use the Windows OpenSSH server as a jumphost. You'll likely need to install it and configure the firewall rules (also covered in that doc).

Then, from Debian, you can:

ssh <windows_username>@$(hostname).local

The $(hostname).local uses mDNS to connect to the Windows host. From there, you can "jump" to your Pi with ssh npi.

You can also shortcut it a bit and just specify the jumphost directly from Debian with something like:

ssh -A -J <windows_user>@$(hostname).local <npi_username>@npi

As you noted in the comments (for other readers), you can also simplify this further with a ~/.ssh/config file as documented here. You'll need to hardcode the Windows hostname, in that case, with the output of echo $(hostname).local.

With a config in place, you can be back to simply:

ssh npi

Other services

If you need to access other services on the RPi from WSL2/Debian, then you can still use SSH tunneling to forward the required ports between the two.

Public-private key authentication.

In short, add the public key of the WSL system to your Windows system using this answer.

Following that, add your WSL public key to the Raspberry Pi. You can again "jump", using the following command (executed form WSL):

ssh-copy-id -o ProxyJump=<windows_username>@<windows_hostname>.local <Pi-username>@<Pi-hostname>
Related Question