11.5. Creating a custom policy for USB devices
The following procedure contains steps for creating a rule set for USB devices that reflects the requirements of your scenario.
Prerequisites
-
The
usbguardservice is installed and running. -
The
/etc/usbguard/rules.conffile contains an initial rule set generated by theusbguard generate-policycommand.
Procedure
Create a policy which authorizes the currently connected USB devices, and store the generated rules to the
rules.conffile:# usbguard generate-policy --no-hashes > ./rules.confThe
--no-hashesoption does not generate hash attributes for devices. Avoid hash attributes in your configuration settings because they might not be persistent.In the
rules.conffile, add, remove, or edit the rules as required by using a text editor. For example, the following rule allows only devices with a single mass storage interface to interact with the system:allow with-interface equals { 08:*:* }See the
usbguard-rules.conf(5)man page for a detailed rule-language description and more examples.Install the updated policy:
# install -m 0600 -o root -g root rules.conf /etc/usbguard/rules.confRestart the
usbguarddaemon to apply your changes:# systemctl restart usbguard
Verification
Check that your custom rules are in the active policy, for example:
# usbguard list-rules ... 4: allow with-interface 08:*:* ...