Windows USB/IP (usbipd)

Share USB devices from Windows to WSL2 or remote machines using usbipd-win.


Installation

Windows (Host)

1# Install usbipd-win
2winget install --interactive --exact dorssel.usbipd-win
3
4# Or download from GitHub
5# https://github.com/dorssel/usbipd-win/releases
6
7# Verify installation
8usbipd --version

WSL2 (Client)

1# Update WSL
2wsl --update
3
4# Inside WSL, install USB/IP tools
5sudo apt install linux-tools-generic hwdata
6sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*-generic/usbip 20

List USB Devices

1# List all USB devices
2usbipd list
3
4# Example output:
5# BUSID  VID:PID    DEVICE                                            STATE
6# 1-1    046d:c52b  Logitech USB Input Device                         Not shared
7# 1-2    0bda:0129  Realtek USB 2.0 Card Reader                       Not shared
8# 2-3    8087:0026  Intel(R) Wireless Bluetooth(R)                    Not shared

Share USB Device to WSL

Bind Device

1# Bind device (makes it shareable)
2usbipd bind --busid 1-1
3
4# Verify
5usbipd list
6# STATE should show "Shared"

Attach to WSL

1# Attach to default WSL distribution
2usbipd attach --wsl --busid 1-1
3
4# Attach to specific distribution
5usbipd attach --wsl --distribution Ubuntu --busid 1-1
6
7# Auto-attach (attach automatically when device is connected)
8usbipd bind --busid 1-1 --auto-attach

Verify in WSL

 1# Inside WSL, check if device is attached
 2lsusb
 3
 4# Check device details
 5lsusb -v -d 046d:c52b
 6
 7# Check kernel messages
 8dmesg | tail
 9
10# List USB devices
11ls -l /dev/bus/usb/*/*

Detach USB Device

1# Detach from WSL
2usbipd detach --busid 1-1
3
4# Unbind (stop sharing)
5usbipd unbind --busid 1-1

Common Use Cases

Serial Device (Arduino, ESP32)

1# Windows: Find device
2usbipd list | findstr "Serial"
3
4# Bind and attach
5usbipd bind --busid 1-4
6usbipd attach --wsl --busid 1-4
 1# WSL: Access serial device
 2ls -l /dev/ttyUSB*
 3ls -l /dev/ttyACM*
 4
 5# Set permissions
 6sudo chmod 666 /dev/ttyUSB0
 7
 8# Or add user to dialout group
 9sudo usermod -a -G dialout $USER
10
11# Test with screen
12screen /dev/ttyUSB0 115200
13
14# Or minicom
15sudo apt install minicom
16minicom -D /dev/ttyUSB0 -b 115200

USB Storage

1# Attach USB drive
2usbipd attach --wsl --busid 2-1
1# WSL: Mount USB drive
2sudo mkdir /mnt/usb
3sudo mount /dev/sdb1 /mnt/usb
4
5# Unmount
6sudo umount /mnt/usb

Webcam

1# Attach webcam
2usbipd attach --wsl --busid 1-3
1# WSL: Check video devices
2ls -l /dev/video*
3
4# Test with v4l2
5sudo apt install v4l-utils
6v4l2-ctl --list-devices
7
8# Capture image
9ffmpeg -f v4l2 -i /dev/video0 -frames 1 capture.jpg

Hardware Security Key (YubiKey)

1# Attach YubiKey
2usbipd attach --wsl --busid 1-5
1# WSL: Verify YubiKey
2lsusb | grep Yubico
3
4# Install tools
5sudo apt install yubikey-manager
6
7# Test
8ykman info

Share USB Over Network

Server (Windows)

1# Bind device for network sharing
2usbipd bind --busid 1-1
3
4# Start server (listens on port 3240)
5usbipd server

Client (Linux)

 1# Install usbip
 2sudo apt install linux-tools-generic
 3
 4# List remote devices
 5usbip list --remote=192.168.1.100
 6
 7# Attach remote device
 8sudo usbip attach --remote=192.168.1.100 --busid=1-1
 9
10# List attached devices
11usbip port
12
13# Detach
14sudo usbip detach --port=00

Automation

PowerShell Script

 1# auto-attach-usb.ps1
 2$BUSID = "1-1"
 3
 4# Wait for device
 5while ($true) {
 6    $device = usbipd list | Select-String -Pattern $BUSID
 7    if ($device -match "Not attached") {
 8        Write-Host "Attaching device $BUSID..."
 9        usbipd attach --wsl --busid $BUSID
10        break
11    }
12    Start-Sleep -Seconds 2
13}

WSL Startup Script

 1# ~/.bashrc or ~/.zshrc
 2
 3# Auto-mount USB drive
 4if [ -b /dev/sdb1 ] && ! mountpoint -q /mnt/usb; then
 5    sudo mkdir -p /mnt/usb
 6    sudo mount /dev/sdb1 /mnt/usb
 7fi
 8
 9# Auto-set serial permissions
10if [ -e /dev/ttyUSB0 ]; then
11    sudo chmod 666 /dev/ttyUSB0
12fi

Troubleshooting

Device Not Showing in WSL

1# Windows: Check if attached
2usbipd list
3
4# Detach and reattach
5usbipd detach --busid 1-1
6usbipd attach --wsl --busid 1-1
1# WSL: Reload USB modules
2sudo modprobe -r usbip_core
3sudo modprobe usbip_core
4
5# Check kernel messages
6dmesg | grep -i usb

Permission Denied

1# WSL: Add user to groups
2sudo usermod -a -G dialout,plugdev $USER
3
4# Logout and login again
5exit
6wsl
7
8# Or set permissions directly
9sudo chmod 666 /dev/ttyUSB0

Device Busy

1# Windows: Check if device is in use
2# Close applications using the device
3
4# Force detach
5usbipd detach --busid 1-1 --force

WSL Kernel Doesn't Support USB

1# Update WSL kernel
2wsl --update
3
4# Check kernel version (should be 5.10.60.1+)
5uname -r
6
7# If old kernel, update Windows and WSL

Persistent Configuration

Windows Task Scheduler

1# Create scheduled task to auto-attach on boot
2$action = New-ScheduledTaskAction -Execute "usbipd" -Argument "attach --wsl --busid 1-1"
3$trigger = New-ScheduledTaskTrigger -AtStartup
4$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
5
6Register-ScheduledTask -TaskName "USB Auto-Attach" -Action $action -Trigger $trigger -Principal $principal

WSL systemd Service

 1# Create service file
 2sudo nano /etc/systemd/system/usb-setup.service
 3
 4[Unit]
 5Description=USB Device Setup
 6After=network.target
 7
 8[Service]
 9Type=oneshot
10ExecStart=/usr/local/bin/usb-setup.sh
11RemainAfterExit=yes
12
13[Install]
14WantedBy=multi-user.target
15
16# Create script
17sudo nano /usr/local/bin/usb-setup.sh
18
19#!/bin/bash
20# Wait for USB device
21sleep 5
22
23# Set permissions
24if [ -e /dev/ttyUSB0 ]; then
25    chmod 666 /dev/ttyUSB0
26fi
27
28# Make executable
29sudo chmod +x /usr/local/bin/usb-setup.sh
30
31# Enable service
32sudo systemctl enable usb-setup

Security Considerations

  1. Bind only trusted devices - Malicious USB devices can compromise system
  2. Use firewall - Block port 3240 if not sharing over network
  3. Verify device IDs - Check VID:PID before attaching
  4. Limit network sharing - Only share to trusted networks
  5. Monitor attached devices - Regularly check usbipd list

Related Snippets