USB/IP basically forwards USB over IP/Network, as the name implies. Forwarding or sharing sockets, or similar, is an absolute nightmare, so this enables a quick and easy operation.
The only downside is that the device won’t be available on Windows anymore. This is either the case while the device is attached, or even as long as it’s bound (see below for further explanation). This I can live with, as my whole development environment lives within WSL anyway.
Install
Attention
You need to perform the Windows installation in addition to the distro’s specific instructions.
Windows
First, you need to install the usbipd-win software on the Windows side. Some GUI tools automatically install this.
You can also run (from an elevated prompt)
winget install usbipdTip
Make sure to reopen any shell/terminal and check that
uspipd.exeis available on yourPATH.
Set up
Note
You might need to perform some or even all of the following steps using elevated rights.
GUI
The process can be greatly simplified, by installing downloading wsl-usb-manager on the Windows side.
Note
This GUI does not automatically install
usbipd-win! Please download the installer from the release page and install it.
You can do everything you desire from within the GUI, even set up auto attachments, without a hassle.
CLI
First, list available devices using
usbipd.exe listTake note of the BUSID of the desired (smart card) device.
Tip
You can also use the Hardware ID (
VID:PIDcolumn) by using the-iflag instead of the-bone.
Then simply execute
usbipd.exe bind -b BUSIDReplace
BUSID: the one you took note of earlier.
Note
It might be necessary to force this operation with the
-fflag, in which case the device will be unavailable under Windows until you perform anunbind.
Now the only thing left to do is attaching the smart card to WSL
usbipd.exe attach -w -b BUSIDYou can even have it auto-attached with
usbipd.exe attach -w -a -b BUSIDNote
The
bindprocedure is persistent between reboots. Theattachprocedure however isn’t, necessitating a reattachement.This also means forcing the
bindusing-fmakes it unavailable until you explicitly do anunbind, whenattachon the contrary, reinstates control to Windows whenever the device is no longer connected to WSL.
Tip
You can easily check if this worked by observing the
usbipd.execommand output, or by utilizinglsusbfrom theusbutilspackage.
FIDO2
Despite all this, some utilities, for example ssh-keygen, utilize a direct smart card access using, e.g., the /dev/hidraw devices the USB/IP setup produces.
For that to work, I had to set up a udev rule.