How to view USB devices with lsusb
How to View USB devices with lsusb
The `lsusb` command is an essential Linux utility that provides detailed information about USB devices connected to your system. Whether you're a system administrator troubleshooting hardware issues, a developer working with USB peripherals, or a curious user wanting to understand your system better, mastering `lsusb` is invaluable for effective USB device management and diagnostics.
This comprehensive guide will walk you through everything you need to know about using `lsusb`, from basic usage to advanced troubleshooting techniques. You'll learn how to interpret USB device information, identify problematic hardware, and leverage various command options to extract specific details about your USB ecosystem.
Table of Contents
- [Prerequisites and Requirements](#prerequisites-and-requirements)
- [Understanding USB Basics](#understanding-usb-basics)
- [Installing lsusb](#installing-lsusb)
- [Basic lsusb Usage](#basic-lsusb-usage)
- [Understanding lsusb Output](#understanding-lsusb-output)
- [Advanced lsusb Options](#advanced-lsusb-options)
- [Practical Examples and Use Cases](#practical-examples-and-use-cases)
- [Troubleshooting Common Issues](#troubleshooting-common-issues)
- [Best Practices and Professional Tips](#best-practices-and-professional-tips)
- [Integration with Other Tools](#integration-with-other-tools)
- [Conclusion](#conclusion)
Prerequisites and Requirements
Before diving into `lsusb` usage, ensure you have the following prerequisites:
System Requirements
- Linux-based operating system (Ubuntu, Debian, CentOS, RHEL, Fedora, etc.)
- Root or sudo privileges for certain advanced operations
- Basic familiarity with command-line interface
- Understanding of fundamental Linux commands
Hardware Requirements
- At least one USB port on your system
- USB devices for testing and practice
- Functional USB subsystem in your kernel
Knowledge Prerequisites
- Basic Linux command-line navigation
- Understanding of file permissions and user privileges
- Familiarity with package management systems
Understanding USB Basics
Before exploring `lsusb`, it's crucial to understand fundamental USB concepts that will help you interpret the command's output effectively.
USB Architecture Overview
USB (Universal Serial Bus) operates on a hierarchical structure consisting of:
USB Controllers: Hardware components that manage USB communication
USB Hubs: Devices that expand the number of available USB ports
USB Devices: End-point devices like keyboards, mice, storage devices, and cameras
USB Identification System
Every USB device is identified by several key parameters:
Vendor ID (VID): A 4-digit hexadecimal number identifying the manufacturer
Product ID (PID): A 4-digit hexadecimal number identifying the specific product
Device Class: Categorizes the device type (storage, input, audio, etc.)
USB Version: Specifies USB standard compatibility (1.0, 1.1, 2.0, 3.0, 3.1, 3.2)
Installing lsusb
The `lsusb` command is typically included in the `usbutils` package, which is pre-installed on most Linux distributions. However, if it's missing from your system, here's how to install it:
Ubuntu/Debian Systems
```bash
sudo apt update
sudo apt install usbutils
```
CentOS/RHEL/Fedora Systems
```bash
For CentOS/RHEL 7 and older
sudo yum install usbutils
For CentOS/RHEL 8+ and Fedora
sudo dnf install usbutils
```
Arch Linux
```bash
sudo pacman -S usbutils
```
Verification
After installation, verify `lsusb` is available:
```bash
lsusb --version
```
Basic lsusb Usage
The simplest way to use `lsusb` is without any arguments, which displays all USB devices currently connected to your system.
Simple Device Listing
```bash
lsusb
```
This command produces output similar to:
```
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2a Intel Corp.
Bus 001 Device 002: ID 0bda:58f4 Realtek Semiconductor Corp.
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 Format
Each line represents a USB device with the following structure:
```
Bus [XXX] Device [YYY]: ID [VVVV]:[PPPP] [Manufacturer] [Product Description]
```
Where:
- XXX: Bus number (3-digit decimal)
- YYY: Device number (3-digit decimal)
- VVVV: Vendor ID (4-digit hexadecimal)
- PPPP: Product ID (4-digit hexadecimal)
Understanding lsusb Output
Interpreting Device Information
Let's analyze a typical `lsusb` output line in detail:
```
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
```
Bus 001: This device is connected to USB bus number 1
Device 004: This is device number 4 on that bus
ID 046d:c52b: Vendor ID is 046d (Logitech), Product ID is c52b
Logitech, Inc. Unifying Receiver: Human-readable manufacturer and product name
USB Bus Hierarchy
USB buses represent different USB controllers on your system. Modern computers typically have multiple buses:
- Bus 001: Often USB 2.0 controller
- Bus 002: Often USB 3.0 controller
- Additional buses for extra controllers
Root Hubs
Root hubs appear in `lsusb` output as:
```
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
```
These represent the USB controllers themselves and are always Device 001 on each bus.
Advanced lsusb Options
Verbose Output (-v)
The verbose option provides extensive technical details about USB devices:
```bash
lsusb -v
```
Warning: This command produces substantial output and may require root privileges for complete information.
For specific devices, combine with device selection:
```bash
lsusb -v -d 046d:c52b
```
Tree View (-t)
Display USB device hierarchy in tree format:
```bash
lsusb -t
```
Output example:
```
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
|__ Port 3: Dev 2, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 3: Dev 2, If 1, Class=Wireless, Driver=btusb, 12M
|__ Port 6: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 12M
```
Device Selection Options
Select by Vendor and Product ID:
```bash
lsusb -d 046d:c52b
```
Select by Vendor ID only:
```bash
lsusb -d 046d:
```
Select by Bus and Device Number:
```bash
lsusb -s 001:004
```
Select by Bus only:
```bash
lsusb -s 001:
```
Descriptor Information
Display specific descriptor types:
```bash
Device descriptor
lsusb -v -d 046d:c52b | grep -A 20 "Device Descriptor"
Configuration descriptor
lsusb -v -d 046d:c52b | grep -A 10 "Configuration Descriptor"
```
Practical Examples and Use Cases
Example 1: Identifying Unknown USB Devices
When you connect an unknown device, use `lsusb` to identify it:
```bash
Before connecting device
lsusb > before.txt
Connect device
After connecting device
lsusb > after.txt
Compare to find new device
diff before.txt after.txt
```
Example 2: Troubleshooting USB Storage Devices
For USB storage devices not mounting properly:
```bash
List all storage-class devices
lsusb -v | grep -E "(Bus|idVendor|idProduct|bInterfaceClass.*Mass Storage)"
Check specific device details
lsusb -v -d 090c:1000 | grep -E "(MaxPower|bcdUSB|bDeviceClass)"
```
Example 3: Monitoring USB Device Changes
Create a simple 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 -t
sleep 2
done
```
Example 4: Extracting Device Information for Documentation
Generate a comprehensive USB device report:
```bash
#!/bin/bash
usb_report.sh
echo "=== USB Device Report ===" > usb_report.txt
echo "Generated: $(date)" >> usb_report.txt
echo "" >> usb_report.txt
echo "=== Device List ===" >> usb_report.txt
lsusb >> usb_report.txt
echo "" >> usb_report.txt
echo "=== Device Tree ===" >> usb_report.txt
lsusb -t >> usb_report.txt
echo "" >> usb_report.txt
echo "Report saved to usb_report.txt"
```
Example 5: Checking USB Power Consumption
Identify power-hungry USB devices:
```bash
lsusb -v | grep -E "(Bus|idProduct|MaxPower)" | paste - - -
```
Troubleshooting Common Issues
Issue 1: lsusb Command Not Found
Symptoms: `bash: lsusb: command not found`
Solutions:
1. Install usbutils package:
```bash
# Ubuntu/Debian
sudo apt install usbutils
# CentOS/RHEL/Fedora
sudo dnf install usbutils
```
2. Check if command exists in different location:
```bash
which lsusb
find /usr -name lsusb 2>/dev/null
```
Issue 2: Permission Denied for Verbose Output
Symptoms: Some device information missing in verbose mode
Solutions:
1. Run with sudo privileges:
```bash
sudo lsusb -v
```
2. Add user to appropriate groups:
```bash
sudo usermod -a -G plugdev $USER
# Logout and login again
```
Issue 3: Device Not Appearing in lsusb
Symptoms: USB device connected but not visible in `lsusb` output
Diagnostic Steps:
1. Check physical connection:
```bash
dmesg | tail -20
```
2. Verify USB subsystem:
```bash
lsmod | grep usb
```
3. Check kernel messages:
```bash
journalctl -f
# Connect device and observe messages
```
4. Test different USB ports:
```bash
# Try different physical ports
# Check with lsusb after each attempt
```
Issue 4: Incomplete Device Information
Symptoms: Device shows as generic or with limited information
Solutions:
1. Update USB device database:
```bash
sudo update-usbids
```
2. Check for driver issues:
```bash
lsusb -t | grep -A 2 -B 2 "Driver="
```
3. Manually lookup device IDs:
```bash
# Visit https://www.linux-usb.org/usb.ids
# Search for vendor:product ID
```
Issue 5: USB 3.0 Devices Showing as USB 2.0
Symptoms: USB 3.0 devices appearing on USB 2.0 bus
Diagnostic Steps:
1. Check available buses:
```bash
lsusb | grep "root hub"
```
2. Verify USB 3.0 support:
```bash
lspci | grep -i usb
```
3. Check cable and port compatibility:
```bash
# Ensure USB 3.0 cable and port are used
lsusb -t
```
Best Practices and Professional Tips
Security Considerations
1. Regular USB Auditing:
```bash
# Create baseline USB inventory
lsusb > /etc/usb_baseline.txt
# Regular comparison script
#!/bin/bash
if ! diff /etc/usb_baseline.txt <(lsusb) > /dev/null; then
echo "WARNING: USB devices changed!"
lsusb
fi
```
2. Monitor Unauthorized Devices:
```bash
# Log all USB events
echo 'ACTION=="add", SUBSYSTEM=="usb", RUN+="/usr/local/bin/log_usb.sh"' > /etc/udev/rules.d/99-usb-log.rules
```
Performance Optimization
1. Identify USB Bottlenecks:
```bash
# Check USB version and speed
lsusb -v | grep -E "(bcdUSB|MaxPower)" | paste - -
```
2. Optimize Device Placement:
```bash
# Distribute high-bandwidth devices across buses
lsusb -t
```
Automation and Scripting
1. Device Detection Scripts:
```bash
#!/bin/bash
# detect_specific_device.sh
VENDOR_ID="046d"
PRODUCT_ID="c52b"
if lsusb -d ${VENDOR_ID}:${PRODUCT_ID} > /dev/null; then
echo "Target device detected"
exit 0
else
echo "Target device not found"
exit 1
fi
```
2. Automated Reporting:
```bash
# Add to crontab for regular USB audits
0 /6 /usr/local/bin/usb_audit.sh >> /var/log/usb_audit.log 2>&1
```
Documentation and Inventory Management
1. Create Device Database:
```bash
# Generate detailed inventory
lsusb -v | grep -E "(Bus|idVendor|idProduct|iProduct)" > usb_inventory.txt
```
2. Track Device Changes:
```bash
# Version control for USB configurations
git init /etc/usb-configs
lsusb > /etc/usb-configs/current_config.txt
cd /etc/usb-configs && git add . && git commit -m "USB config $(date)"
```
Integration with Other Tools
Combining with dmesg
Monitor real-time USB events:
```bash
Terminal 1: Monitor kernel messages
dmesg -w | grep -i usb
Terminal 2: Monitor lsusb changes
watch -n 1 lsusb
```
Integration with udev
Create custom rules based on lsusb information:
```bash
Get device details
lsusb -v -d 046d:c52b | grep -E "(idVendor|idProduct|iSerial)"
Create udev rule
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c52b", ACTION=="add", RUN+="/usr/local/bin/device_handler.sh"' > /etc/udev/rules.d/99-custom-device.rules
```
Working with lshw and lspci
Comprehensive hardware analysis:
```bash
Complete hardware overview
sudo lshw -short | grep -E "(usb|USB)"
PCI USB controllers
lspci | grep -i usb
Detailed USB controller information
lspci -v | grep -A 10 -i "usb controller"
```
System Information Scripts
Create comprehensive system documentation:
```bash
#!/bin/bash
system_usb_info.sh
echo "=== System USB Information ==="
echo "Date: $(date)"
echo "Hostname: $(hostname)"
echo ""
echo "=== USB Controllers ==="
lspci | grep -i usb
echo ""
echo "=== USB Devices ==="
lsusb
echo ""
echo "=== USB Device Tree ==="
lsusb -t
echo ""
echo "=== USB Storage Devices ==="
lsblk | grep -E "(usb|USB)"
```
Advanced Use Cases
USB Device Development
For developers working with USB devices:
```bash
Monitor descriptor changes during development
watch -n 0.5 'lsusb -v -d 1234:5678 | head -50'
Extract specific descriptor information
lsusb -v -d 1234:5678 | sed -n '/Device Descriptor/,/Configuration Descriptor/p'
```
System Administration
Enterprise USB management:
```bash
#!/bin/bash
enterprise_usb_audit.sh
LOGFILE="/var/log/usb_audit.log"
ALERT_EMAIL="admin@company.com"
Current USB devices
CURRENT_DEVICES=$(lsusb | wc -l)
BASELINE_DEVICES=$(cat /etc/usb_baseline_count 2>/dev/null || echo "0")
if [ "$CURRENT_DEVICES" -ne "$BASELINE_DEVICES" ]; then
echo "$(date): USB device count changed from $BASELINE_DEVICES to $CURRENT_DEVICES" >> $LOGFILE
lsusb >> $LOGFILE
echo "USB audit alert" | mail -s "USB Device Change Detected" $ALERT_EMAIL
fi
echo $CURRENT_DEVICES > /etc/usb_baseline_count
```
Forensics and Security Analysis
USB forensics applications:
```bash
Capture USB device timeline
#!/bin/bash
usb_timeline.sh
TIMELINE_FILE="/var/log/usb_timeline.log"
while true; do
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
DEVICE_COUNT=$(lsusb | wc -l)
echo "$TIMESTAMP: $DEVICE_COUNT devices" >> $TIMELINE_FILE
# Detailed snapshot every 10 minutes
if [ $(($(date +%M) % 10)) -eq 0 ]; then
echo "$TIMESTAMP: Full device list" >> $TIMELINE_FILE
lsusb >> $TIMELINE_FILE
echo "---" >> $TIMELINE_FILE
fi
sleep 60
done
```
Conclusion
The `lsusb` command is an indispensable tool for anyone working with Linux systems and USB devices. From basic device identification to complex system administration tasks, mastering `lsusb` provides crucial insights into your system's USB ecosystem.
Key Takeaways
1. Basic Usage: `lsusb` without arguments provides a quick overview of all connected USB devices
2. Advanced Options: Verbose mode (-v) and tree view (-t) offer detailed technical information
3. Troubleshooting: Systematic approaches using `lsusb` can resolve most USB-related issues
4. Integration: Combining `lsusb` with other tools creates powerful system administration workflows
5. Security: Regular USB auditing helps maintain system security and compliance
Next Steps
To further enhance your USB management capabilities:
1. Explore udev Rules: Learn to create custom device handling rules
2. Study USB Standards: Deepen understanding of USB protocols and specifications
3. Practice Scripting: Develop automated USB monitoring and management scripts
4. Security Hardening: Implement USB device whitelisting and monitoring
5. Performance Tuning: Optimize USB device placement and configuration
Additional Resources
- USB-IF Official Documentation: Understanding USB standards and specifications
- Linux USB Subsystem Documentation: Kernel-level USB implementation details
- udev Manual Pages: Advanced device management and rule creation
- System Security Frameworks: USB security policies and implementation
By mastering `lsusb` and implementing the practices outlined in this guide, you'll be well-equipped to handle any USB-related challenges in your Linux environment. Whether you're troubleshooting hardware issues, managing enterprise systems, or developing USB applications, the knowledge and techniques presented here will serve as a solid foundation for your continued success.
Remember that effective USB management is an ongoing process that requires regular monitoring, documentation, and adaptation to new technologies and security requirements. Stay current with USB standards evolution and continue practicing with different devices and scenarios to maintain your expertise.