Share USB over Network with USB/IP on Linux: Connect USB Tokens and License Dongles to KVM/Proxmox VMs

Virtualization tutorial - IT technology blog
Virtualization tutorial - IT technology blog

Background & Real-World Issues

Sysadmins managing Proxmox VE or KVM clusters are likely familiar with this scenario: the accounting department constantly calling because MISA or FAST software lost its Viettel-CA digital signature, or the company ERP app suddenly crashing because it can’t detect the SafeNet Sentinel dongle.

The traditional workaround is plugging the USB directly into the physical server and enabling USB Passthrough to the virtual machine (VM). It works fine as a temporary fix. But in a production cluster, you’ll immediately run into several headaches:

  • Losing Live Migration and High Availability (HA): Hardcoding a physical port to a VM anchors that virtual machine to that specific node. When the node needs maintenance, moving the VM to another node is completely out of the question.
  • Servers located far away in the Data Center: Every time accounting switches to a new bank token, nobody wants to drive 20 kilometers to the DC just to unplug and replug a USB key.
  • Lack of flexibility: Borrowing a token for 15 minutes to test a staging build requires opening the hypervisor UI, reconfiguring hardware, and often rebooting the VM.

In my 3-node Proxmox homelab running 12 VMs and containers, I repurposed a Raspberry Pi 4 (2GB RAM) sitting on my desk as a dedicated USB Server. It captures the signals from the tokens and forwards them across the LAN to virtual machines over raw TCP/IP using USB/IP. For over 6 months with 4 tokens plugged in 24/7, the setup has handled everything smoothly—from electronic tax filings to invoice signing—with network latency staying under 1ms.

Prerequisites & Package Installation

The setup consists of two machines: the USB Server (a Raspberry Pi or mini Linux PC hosting the physical USB devices) and the USB Client (the KVM/Proxmox VM that needs to use them). Both run Ubuntu 22.04/24.04 or Debian 12.

1. Setup on the USB Server

The usbip package is available directly in the standard Debian and Ubuntu repositories:

sudo apt update
sudo apt install -y usbip linux-tools-generic hwdata

Load the two required kernel modules so the host can share its USB ports:

sudo modprobe usbip_core
sudo modprobe usbip_host

# Configure modules to load automatically on boot
echo "usbip_core" | sudo tee -a /etc/modules
echo "usbip_host" | sudo tee -a /etc/modules

2. Setup on the USB Client (Target VM)

On the target VM, you only need to load the driver that creates virtual USB ports, vhci-hcd (Virtual Host Controller Interface):

sudo apt update
sudo apt install -y usbip linux-tools-generic

sudo modprobe vhci-hcd
echo "vhci-hcd" | sudo tee -a /etc/modules

Step-by-Step Configuration

Step 1: Start the Daemon on the USB Server

Start the usbipd daemon in the background on its default port, 3240/tcp:

sudo usbipd -D

List all USB devices currently plugged into the server:

usbip list -l

The terminal will return output similar to this:

 - busid 1-1.2 (096e:0807)
   Feitian Technologies, Inc. : ePass2003 (USB Token)

 - busid 1-1.4 (04b9:1202)
   SafeNet Inc. : Sentinel Hardware Key (Dongle License)

Note down the busid value of the device you want to use. Here, the ePass2003 token has a busid of 1-1.2.

Step 2: Bind the Device to the Network

Hand over management of the device to the USB/IP driver:

sudo usbip bind -b 1-1.2

Once the command runs, the device is immediately ready to accept remote connections.

Step 3: Attach the Device to the Virtual Machine

Open a terminal on the KVM VM. Assuming the USB Server IP is 192.168.1.50, run a quick query to see which devices the server is exposing:

usbip list -r 192.168.1.50

Attach the token to the VM with a single command:

sudo usbip attach -r 192.168.1.50 -b 1-1.2

Verify the result using lsusb:

lsusb

The device name Feitian ePass2003 appears cleanly, just as if it were plugged directly into the physical chassis.

Step 4: Auto-reconnect with a Systemd Service

Local networks can flicker occasionally. Furthermore, every time the VM restarts, virtual port attachments are lost. Create a systemd service to automatically reattach the device upon boot.

Create the file /etc/systemd/system/usbip-client.service on the VM:

[Unit]
Description=USB-IP Client Auto Attach
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/sbin/modprobe vhci-hcd
ExecStart=/usr/bin/usbip attach -r 192.168.1.50 -b 1-1.2
ExecStop=/usr/bin/usbip detach -p 0
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Reload the systemd daemon and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable --now usbip-client.service

Operation, Monitoring & Troubleshooting

1. Check Virtual USB Port Status

Run the following command on the VM to see where the virtual port is mapped:

usbip port

The output will show:

Port 00: <Port in Use> at Full Speed(12Mbps)
       Feitian Technologies, Inc. : ePass2003 (096e:0807)
       -> usbip://192.168.1.50:3240/1-1.2
       -> remote bus/dev 001/005

2. Safely Detach Devices

Need to move the token to a test VM? Don’t just yank the hardware out.

# 1. On the VM: Detach virtual port 00
sudo usbip detach -p 0

# 2. On the USB Server: Return device control to the host
sudo usbip unbind -b 1-1.2

3. Two Common Issues and Quick Fixes

  • Port 3240 blocked: If the client cannot discover devices, it’s usually blocked by the server firewall. Open it quickly with: sudo ufw allow 3240/tcp.
  • Bus ID changes when plugged into a different slot: Unplugging the USB and inserting it into another port changes the busid (e.g., from 1-1.2 to 1-1.3), breaking the systemd script. Mark the physical port with colored tape, or use a bash script to dynamically look up the busid by VendorID:ProductID (e.g., 096e:0807) before running the bind command.
Share: