I'm using the RPI to create a program, but I need to disable the USB ports so that the end user cannot plug in a keyboard or mouse and mess with the device.
Is this possible, and if so how is it done?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.Sign up to join this community
Each USB host controller in Linux exposes a setting called
authorized_default, which controls the state of any new connected devices. Setting it to 0 makes all new devices disabled by default:
for host in /sys/bus/usb/devices/usb*; do echo 0 > $host/authorized_default; done
A recommended way of running this script consists in using
udev rules. This way, you're sure the script runs at the right time, when the host controller driver is already loaded, but none of the devices have yet been authorised. See this question for an example of this approach.
One thing you should understand is that software locks are only effective as long as the end user cannot unplug the SD card and remove the protections you have put in place.