How to list USB devices → lsusb

How to List USB devices → lsusb Table of Contents 1. [Introduction](#introduction) 2. [Prerequisites](#prerequisites) 3. [Understanding USB Basics](#understanding-usb-basics) 4. [Installing lsusb](#installing-lsusb) 5. [Basic lsusb Usage](#basic-lsusb-usage) 6. [Advanced lsusb Options](#advanced-lsusb-options) 7. [Practical Examples and Use Cases](#practical-examples-and-use-cases) 8. [Understanding lsusb Output](#understanding-lsusb-output) 9. [Alternative Methods](#alternative-methods) 10. [Troubleshooting Common Issues](#troubleshooting-common-issues) 11. [Best Practices and Tips](#best-practices-and-tips) 12. [Conclusion](#conclusion) Introduction The `lsusb` command is an essential utility for Linux system administrators, developers, and power users who need to identify, troubleshoot, and manage USB devices connected to their systems. This comprehensive guide will teach you everything you need to know about using `lsusb` effectively, from basic device listing to advanced diagnostic techniques. USB (Universal Serial Bus) devices are ubiquitous in modern computing environments. Whether you're troubleshooting hardware issues, developing device drivers, performing security audits, or simply wanting to understand what devices are connected to your system, `lsusb` provides the detailed information you need. By the end of this guide, you'll understand how to: - List all USB devices connected to your system - Interpret detailed device information - Use advanced filtering and formatting options - Troubleshoot USB connectivity issues - Implement best practices for USB device management Prerequisites Before diving into `lsusb` usage, ensure you have the following: System Requirements - Linux-based operating system (Ubuntu, CentOS, Debian, Fedora, etc.) - Terminal access with basic command-line knowledge - Administrative privileges (sudo access) for certain operations Knowledge Prerequisites - Basic understanding of Linux command-line interface - Familiarity with USB device concepts - Understanding of system administration basics Hardware Requirements - At least one USB port on your system - USB devices for testing (optional but recommended) Understanding USB Basics USB Architecture Overview USB follows a tree-like hierarchical structure where devices connect through hubs and controllers. Understanding this architecture helps interpret `lsusb` output effectively. Key Components: - USB Host Controller: Manages USB communication - USB Hubs: Provide additional connection points - USB Devices: End-point devices like keyboards, mice, storage devices - USB Endpoints: Communication channels within devices USB Device Classes USB devices are categorized into standard classes: - HID (Human Interface Device): Keyboards, mice, game controllers - Mass Storage: USB drives, external hard disks - Audio: USB speakers, microphones, audio interfaces - Video: Webcams, capture devices - Communication: USB modems, network adapters - Hub: USB hubs and controllers USB Specifications Different USB versions offer varying speeds and capabilities: - USB 1.1: Low Speed (1.5 Mbps), Full Speed (12 Mbps) - USB 2.0: High Speed (480 Mbps) - USB 3.0/3.1: SuperSpeed (5 Gbps/10 Gbps) - USB 3.2: SuperSpeed+ (20 Gbps) - USB4: Up to 40 Gbps Installing lsusb Ubuntu/Debian Systems The `lsusb` command is part of the `usbutils` package: ```bash Update package list sudo apt update Install usbutils package sudo apt install usbutils Verify installation lsusb --version ``` CentOS/RHEL/Fedora Systems For Red Hat-based distributions: ```bash CentOS/RHEL 7/8 sudo yum install usbutils Fedora/CentOS Stream/RHEL 9 sudo dnf install usbutils Verify installation lsusb --version ``` Arch Linux ```bash Install usbutils sudo pacman -S usbutils Verify installation lsusb --version ``` Checking Installation Confirm `lsusb` is properly installed: ```bash Check if lsusb is available which lsusb Display help information lsusb --help ``` Basic lsusb Usage Simple Device Listing The most basic usage of `lsusb` displays all connected USB devices: ```bash lsusb ``` Sample Output: ``` Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 8087:0025 Intel Corp. Wireless-AC 9560 Bus 001 Device 002: ID 04f2:b681 Chicony Electronics Co., Ltd Integrated Camera Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub ``` Understanding Basic Output Each line represents a USB device with the following format: ``` Bus [XXX] Device [YYY]: ID [VVVV]:[PPPP] [Manufacturer] [Product Name] ``` Where: - Bus XXX: USB bus number - Device YYY: Device number on the bus - VVVV: Vendor ID (4-digit hexadecimal) - PPPP: Product ID (4-digit hexadecimal) Verbose Output For detailed device information: ```bash lsusb -v ``` This provides comprehensive details including: - Device descriptors - Configuration information - Interface details - Endpoint specifications Warning: Verbose output can be extremely lengthy. Consider using filters or redirecting to a file for analysis. Advanced lsusb Options Filtering by Bus and Device Target specific devices using bus and device numbers: ```bash List specific device lsusb -s 001:004 List all devices on a specific bus lsusb -s 001: ``` Filtering by Vendor and Product ID Use vendor and product IDs for precise device identification: ```bash Filter by vendor ID lsusb -d 046d: Filter by specific vendor and product ID lsusb -d 046d:c52b Filter by product ID only (any vendor) lsusb -d :c52b ``` Tree View Display Visualize USB device hierarchy: ```bash lsusb -t ``` Sample Tree Output: ``` /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M |__ Port 3: Dev 2, If 0, Class=Video, Driver=uvcvideo, 480M |__ Port 5: Dev 3, If 0, Class=Wireless, Driver=btusb, 12M |__ Port 10: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 12M ``` Verbose Information for Specific Devices Combine filtering with verbose output: ```bash Detailed info for specific device lsusb -v -s 001:004 Detailed info for vendor's devices lsusb -v -d 046d: ``` Descriptor Dump Display raw USB descriptors: ```bash Dump descriptors for specific device lsusb -D /dev/bus/usb/001/004 Alternative method using device path sudo lsusb -v -s 001:004 | head -20 ``` Practical Examples and Use Cases Example 1: Identifying Unknown USB Device When you connect an unknown device: ```bash Before connecting device lsusb > before.txt Connect device, then compare lsusb > after.txt diff before.txt after.txt ``` Output: ``` > Bus 001 Device 005: ID 0781:5567 SanDisk Corp. Cruzer Blade ``` Example 2: Troubleshooting USB Storage Device Check if a USB drive is detected: ```bash Look for mass storage devices lsusb | grep -i storage Check detailed information lsusb -v | grep -A 20 -B 5 "Mass Storage" ``` Example 3: Monitoring USB Device Changes Create a monitoring script: ```bash #!/bin/bash usb_monitor.sh echo "Monitoring USB devices. Press Ctrl+C to stop." while true; do clear echo "=== USB Devices at $(date) ===" lsusb sleep 2 done ``` Make it executable and run: ```bash chmod +x usb_monitor.sh ./usb_monitor.sh ``` Example 4: Security Audit - Listing All USB Devices For security assessments: ```bash Generate comprehensive USB device report echo "USB Security Audit - $(date)" > usb_audit.txt echo "================================" >> usb_audit.txt lsusb -v >> usb_audit.txt Extract vendor and product information lsusb | awk '{print $6, $7, $8, $9}' | sort | uniq ``` Example 5: Checking USB Version Support Identify USB version capabilities: ```bash Check for USB 3.0 devices lsusb -t | grep -E "5000M|10000M" List SuperSpeed devices lsusb -v | grep -B 5 -A 5 "bcdUSB.*3\." ``` Example 6: Finding Specific Device Classes Locate devices by class: ```bash Find HID devices lsusb -v | grep -B 10 -A 5 "bInterfaceClass.*3 Human Interface Device" Find audio devices lsusb -v | grep -B 10 -A 5 "bInterfaceClass.*1 Audio" ``` Understanding lsusb Output Device Descriptor Fields When using `lsusb -v`, you'll see various descriptor fields: Device Descriptor ``` Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 9 Hub bDeviceSubClass 0 bDeviceProtocol 1 Single TT bMaxPacketSize0 64 idVendor 0x1d6b Linux Foundation idProduct 0x0002 2.0 root hub bcdDevice 5.04 iManufacturer 3 Linux 5.4.0-74-generic xhci-hcd iProduct 2 xHCI Host Controller iSerial 1 0000:00:14.0 ``` Key Fields Explained: - bcdUSB: USB specification version - bDeviceClass: Device class code - idVendor/idProduct: Unique device identifiers - bcdDevice: Device release number Configuration Descriptor ``` Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x0019 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xe0 Self Powered Remote Wakeup MaxPower 0mA ``` Interface Descriptor ``` Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 9 Hub bInterfaceSubClass 0 bInterfaceProtocol 0 Full speed (or root) hub iInterface 0 ``` USB Class Codes Common USB class codes you'll encounter: | Class | Code | Description | |-------|------|-------------| | Audio | 01h | Audio devices | | CDC | 02h | Communication devices | | HID | 03h | Human Interface Devices | | Physical | 05h | Physical interface devices | | Image | 06h | Still imaging devices | | Printer | 07h | Printer devices | | Mass Storage | 08h | Mass storage devices | | Hub | 09h | USB hubs | | CDC-Data | 0Ah | Data interface | | Smart Card | 0Bh | Smart card devices | | Content Security | 0Dh | Content security devices | | Video | 0Eh | Video devices | | Personal Healthcare | 0Fh | Personal healthcare devices | | Audio/Video | 10h | Audio/video devices | | Billboard | 11h | Billboard device class | | USB Type-C Bridge | 12h | USB Type-C bridge class | Alternative Methods Using /proc/bus/usb (Legacy) On older systems, USB information might be available through `/proc`: ```bash Check if /proc/bus/usb exists ls /proc/bus/usb/ List devices (if available) cat /proc/bus/usb/devices ``` Using /sys/bus/usb The sysfs interface provides detailed USB information: ```bash List USB devices through sysfs find /sys/bus/usb/devices -name "idVendor" -exec dirname {} \; | \ while read device; do echo "Device: $device" echo " Vendor: $(cat $device/idVendor 2>/dev/null)" echo " Product: $(cat $device/idProduct 2>/dev/null)" echo " Manufacturer: $(cat $device/manufacturer 2>/dev/null)" echo " Product Name: $(cat $device/product 2>/dev/null)" echo "" done ``` Using dmesg Monitor USB events through kernel messages: ```bash Show USB-related kernel messages dmesg | grep -i usb Monitor real-time USB events dmesg -w | grep -i usb Show recent USB device connections dmesg | grep -i "new.*usb device" | tail -5 ``` Using udevadm Monitor USB device events: ```bash Monitor USB device events sudo udevadm monitor --subsystem-match=usb Get detailed device information udevadm info --attribute-walk --path=/sys/bus/usb/devices/1-1 ``` Troubleshooting Common Issues Issue 1: lsusb Command Not Found Problem: `bash: lsusb: command not found` Solutions: ```bash Install usbutils package Ubuntu/Debian: sudo apt install usbutils CentOS/RHEL: sudo yum install usbutils Fedora: sudo dnf install usbutils Verify installation which lsusb ``` Issue 2: Permission Denied Errors Problem: Cannot access device information Solutions: ```bash Run with sudo for full access sudo lsusb -v Add user to appropriate groups sudo usermod -a -G plugdev $USER Check USB device permissions ls -la /dev/bus/usb/001/ ``` Issue 3: Device Not Showing Up Problem: Connected USB device doesn't appear in lsusb output Diagnostic Steps: ```bash Check if device is detected by kernel dmesg | tail -20 Verify USB ports are working lsusb -t Check for power issues cat /sys/bus/usb/devices/*/power/control Test different USB ports Try connecting device to different ports ``` Issue 4: Incomplete Device Information Problem: Device shows up but with limited information Solutions: ```bash Update USB ID database sudo update-usbids Check if device requires specific drivers lsmod | grep usb Verify device is properly enumerated lsusb -v -s [bus]:[device] ``` Issue 5: USB 3.0 Devices Showing as USB 2.0 Problem: SuperSpeed devices operating at lower speeds Diagnostic Steps: ```bash Check USB controller capabilities lspci | grep -i usb Verify USB 3.0 support lsusb -t | grep -E "5000M|10000M" Check if USB 3.0 drivers are loaded lsmod | grep xhci ``` Issue 6: Intermittent Device Recognition Problem: USB device occasionally disappears from lsusb output Solutions: ```bash Monitor USB events sudo udevadm monitor --subsystem-match=usb Check for power management issues echo 'on' | sudo tee /sys/bus/usb/devices/*/power/control Disable USB autosuspend temporarily echo -1 | sudo tee /sys/module/usbcore/parameters/autosuspend ``` Best Practices and Tips 1. Regular USB Auditing Create automated scripts for regular USB device auditing: ```bash #!/bin/bash usb_audit_daily.sh DATE=$(date +%Y%m%d) LOGFILE="/var/log/usb_audit_$DATE.log" echo "Daily USB Audit - $(date)" > $LOGFILE echo "================================" >> $LOGFILE lsusb >> $LOGFILE echo "" >> $LOGFILE echo "Detailed Information:" >> $LOGFILE lsusb -v >> $LOGFILE 2>&1 ``` 2. USB Device Whitelist Management Implement USB device control: ```bash #!/bin/bash usb_whitelist_check.sh WHITELIST_FILE="/etc/usb_whitelist.txt" CURRENT_DEVICES=$(lsusb | awk '{print $6}') for device in $CURRENT_DEVICES; do if ! grep -q "$device" "$WHITELIST_FILE"; then echo "WARNING: Unauthorized USB device detected: $device" logger "Unauthorized USB device: $device" fi done ``` 3. Performance Monitoring Monitor USB device performance: ```bash Check USB transfer speeds sudo hdparm -tT /dev/sdX # For USB storage devices Monitor USB bandwidth usage iotop -a # Shows I/O activity including USB devices ``` 4. Documentation and Logging Maintain comprehensive USB device logs: ```bash Create detailed device inventory lsusb -v | grep -E "(Bus|Device|idVendor|idProduct|iManufacturer|iProduct)" > usb_inventory.txt Log device changes echo "$(date): USB device inventory updated" >> /var/log/usb_changes.log ``` 5. Security Considerations Implement USB security measures: ```bash Disable USB storage (if required) echo 'install usb-storage /bin/true' | sudo tee -a /etc/modprobe.d/blacklist-usb-storage.conf Monitor for new USB devices inotifywait -m /dev/bus/usb/ -e create -e delete --format '%w%f %e %T' --timefmt '%Y-%m-%d %H:%M:%S' ``` 6. Troubleshooting Workflow Follow systematic troubleshooting: 1. Initial Check: `lsusb` - Is device detected? 2. Detailed Analysis: `lsusb -v -s [bus]:[device]` 3. Kernel Messages: `dmesg | grep -i usb` 4. Driver Status: `lsmod | grep [driver_name]` 5. Hardware Test: Try different ports/cables 6. Permission Check: Verify user permissions 7. Automation and Integration Integrate lsusb into monitoring systems: ```bash Nagios/Icinga check script #!/bin/bash EXPECTED_DEVICES=5 CURRENT_COUNT=$(lsusb | wc -l) if [ $CURRENT_COUNT -ne $EXPECTED_DEVICES ]; then echo "CRITICAL: Expected $EXPECTED_DEVICES USB devices, found $CURRENT_COUNT" exit 2 else echo "OK: All expected USB devices present" exit 0 fi ``` 8. Cross-Platform Considerations When working across different Linux distributions: ```bash Universal USB utils installation check if ! command -v lsusb &> /dev/null; then if command -v apt &> /dev/null; then sudo apt install usbutils elif command -v yum &> /dev/null; then sudo yum install usbutils elif command -v dnf &> /dev/null; then sudo dnf install usbutils elif command -v pacman &> /dev/null; then sudo pacman -S usbutils fi fi ``` Conclusion The `lsusb` command is an indispensable tool for anyone working with USB devices on Linux systems. This comprehensive guide has covered everything from basic device listing to advanced troubleshooting techniques and security considerations. Key Takeaways 1. Basic Usage: `lsusb` provides quick device enumeration 2. Advanced Options: Filtering and verbose output offer detailed insights 3. Troubleshooting: Systematic approach using multiple diagnostic tools 4. Security: Regular auditing and monitoring prevent unauthorized access 5. Automation: Scripts and monitoring integration enhance system management Next Steps To further enhance your USB device management skills: 1. Explore udev Rules: Learn to create custom device handling rules 2. Study USB Specifications: Understand USB protocol details 3. Practice Driver Development: Develop custom USB device drivers 4. Implement Monitoring: Set up comprehensive USB device monitoring 5. Security Hardening: Implement advanced USB security measures Additional Resources - USB.org: Official USB specifications and documentation - Linux USB Project: Kernel USB subsystem documentation - udev Manual: Device management and rule creation - sysfs Documentation: Understanding the Linux device filesystem By mastering `lsusb` and related tools, you'll be well-equipped to handle any USB device management challenge in your Linux environment. Whether you're troubleshooting connectivity issues, performing security audits, or developing USB-related applications, the knowledge gained from this guide will serve as a solid foundation for your continued learning and professional development. Remember to always follow security best practices when working with USB devices, especially in enterprise environments, and keep your system and USB utilities updated to ensure optimal performance and security.