Basically, USBGuard prevents all unauthorized USB devices from connecting to your machine.
Start by installing it, if you’re running Ubuntu, Debian or other Debian-based distros:
| |
Or, if you’re running Fedora:
| |
Make sure all USB devices that you want to be allowed by default to connect to your system are plugged in (don’t worry about the built-in USB devices, like your laptop webcam or Bluetooth module, they get whitelisted automatically), and generate the default policy:
| |
- Note
- A simpler sudo usbguard generate-policy > /etc/usbguard/rules.conf command won’t work (you will get a Permission denied error) simply because of the way redirection (>, », also piping with |) works in Linux: it’s done by the current shell and always performed as the current user regardless of the sudo part.
If your Linux distro has systemd, enable usbguard service on startup:
| |
Or, if your Linux distro uses System-V style init scripts (whoop whoop Devuan), use update-rc.d:
| |
Whenever you want to allow a new device, plug it into an USB port and use:
| |
to find the device rule number. Now you can allow this specific device to connect to your system temporarily:
| |
Or if you want to allow it permanently:
| |
Done.