On Ubuntu 16.04 or above
sudo apt install usbguard
After plugging any should allowed USB device execute below commands in same order;
And off course after unplugging should not allowed USB devices execute below commands too;
sudo usbguard generate-policy > rules.conf
sudo install -m 0600 -o root -g root rules.conf /etc/usbguard/rules.conf
sudo systemctl restart usbguard