Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux USB Security Settings: How to Lock Down USB Ports

· 5 min read · Home Security

In this article
  1. The Six Settings That Control USB Access
  2. Why There Is No Single USB Settings Screen
  3. Blocking USB Storage Drives Entirely
  4. Allow-Lists and Per-Device Authorization With udev
  5. BadUSB and Why Port Blocking Is Not the Whole Story
  6. What to Check Before and After Changing Anything
  7. Everyday Rules of Thumb

Yes, you can restrict USB devices on Linux, and there is no single settings screen for it. USB security is handled through a kernel setting called usb-storage authorization, udev rules, and physical port control, so you pick the layer that matches the threat you are blocking.

Time 30 min · Steps 6 · Level Advanced

The Six Settings That Control USB Access

  1. Disable USB storage at boot. Blacklist the usb-storage kernel module so no mass-storage device (USB sticks and portable drives) can mount at all.
  2. Require authorization per port. Use the kernel's built-in authorization feature so each newly plugged device stays inert until an administrator allows it.
  3. Write udev rules for allow-lists. Match devices by vendor and product ID so only your known keyboards, mice and drives get permission to run.
  4. Lock the BIOS/UEFI too. Disable unused USB ports or boot-from-USB in firmware, because kernel rules do not apply before the OS loads.
  5. Restrict physical access. Ports in public areas, meeting rooms and reception desks are the ones that matter most; lock cases or use port locks where practical.
  6. Watch what is already connected. Audit current devices with the lsusb command so you know your baseline before changing anything.

Why There Is No Single USB Settings Screen

Unlike Windows, which exposes device restrictions through Group Policy, Linux treats USB as a kernel-level concern. The kernel loads a driver module for each device class, and security is enforced at the moment a device is plugged in, not through a control panel. That is actually good news: the controls are powerful and consistent across desktop environments like GNOME and KDE, because they live below the desktop layer. The trade-off is that most of the work happens in a terminal with administrator (sudo) privileges.

Blocking USB Storage Drives Entirely

If your goal is simply "no USB sticks on this machine," the usb-storage module is the switch. Open a terminal and run sudo modprobe -r usb-storage to unload it for the current session, then add the line blacklist usb-storage to a file such as /etc/modprobe.d/block-usb.conf so it never loads at boot. After a reboot, a plugged-in USB drive gets power but no storage driver, so nothing mounts and no files appear. This blocks storage only; keyboards, mice and network adapters keep working, which is usually what you want on a server or a shared workstation.

To undo it, remove the blacklist line and run sudo modprobe usb-storage. Keep a note of any change like this, because six months later "the USB ports stopped working" is a hard problem to diagnose if nobody remembers the blacklist file.

Allow-Lists and Per-Device Authorization With udev

For finer control, udev rules let you approve specific devices and reject everything else. Run lsusb and each device shows a vendor ID and product ID in the form 1234:5678. A udev rule can match that pair and authorize it, while a catch-all rule denies unknown devices. Rules live as .rules files in /etc/udev/rules.d/ and take effect after reloading udev or replugging the device. The exact rule syntax and file layout can differ slightly between distributions, so test on one machine before rolling out to others.

The kernel also has a per-port authorization switch, visible as an "authorized" file under each device's directory in /sys/bus/usb/devices/. Writing 0 there deactivates a device without unplugging it. This is the mechanism most enterprise device-control tools for Linux build on, so if you would rather not hand-write rules, a device-control utility from your distribution's package manager can manage this layer for you.

BadUSB and Why Port Blocking Is Not the Whole Story

A common misconception is that blocking file transfers blocks all USB risk. The bigger threat on an unattended port is a device that pretends to be a keyboard. A malicious USB gadget can enumerate as a human-interface device and type commands faster than any person, with no storage involved at all. This is why allow-lists by vendor and product ID are stronger than a storage-only blacklist: an unexpected keyboard is exactly the device you want stopped at the door. It is also why BIOS-level control matters, since a device can attempt to boot from USB before your rules ever load.

What to Check Before and After Changing Anything

Start with a baseline: run lsusb and note every device, then check lsblk to see which USB drives currently mount and where. After applying your rules, test three cases: a known-good device (should work), an unknown USB stick (should be refused), and a reboot (settings should survive). If a legitimate device stops working, the fastest diagnosis is to unplug it, run sudo dmesg | tail, and replug it; the kernel log shows whether the device was rejected by authorization, udev, or a missing driver. On laptops, remember that some internal components such as webcams and Bluetooth sit on the internal USB bus, so avoid blanket rules that disable the whole bus rather than the external ports.

Everyday Rules of Thumb

For a personal laptop, the practical rule is: disable boot-from-USB in firmware, keep the screen locked, and stop worrying. For a shared or public machine, block usb-storage and rely on passwords for anything sensitive. For a machine holding data that would genuinely hurt if copied, use per-device authorization with an allow-list, and treat every unattended port as an open door. The one habit that covers all of them: never plug in a USB device you found or were handed by a stranger, no matter what settings you have in place.

Official source: The Linux Kernel Documentation