Afaik usb rubber ducky acts as a keyboard and not a regular usb, which allows it to type in hundreds of commands on any computer that it is plugged into in a matter of seconds. What are the measures we can take to prevent such type attacks from happening on the linux platform?
There's a few answers about blacklist/whitelist, but they're mostly referring to udev configuration. But in new kernels there's an official USB authorization framework available.
This allows you to lock down all usb controllers first and then enable only the devices you want.
I was initially going to comment under John Deters answer and say that his is the correct post, at least it offers the OP some advice on how to protect against the attack rather than just stating that if the attacker can physically access your device it's game over. For starters Linux with an encrypted boot loader, disabled USBs, and FDE invalidates that claim immediately. Second, not every computer can be restricted from public access. Library terminals, store kiosks, bank lobby computers, the list goes on...
So to that end, I found a few other ways (in addition to John's answer) that may be useful. Borrowed from this forum post:
User typing will cause any command to fail.
Another window becoming active and stealing keyboard focus will cause the entire process to fail.
HID or USB devices in general can be programmatically blocked, disabled, ejected, etc causing the process to fail.
Linux can white/blacklist USB devices which will cause the process to fail.
Any applications which repurpose key combinations will cause the process to fail.
The device receives no feedback from the host machine and thus is unaware of timing, delays, active windows, etc which will cause the process to fail.
This would mean you do not have sufficient physical security to protect your assets. If an attacker gets access to your physical device, it's not your device anymore.
There are several things to be considered, including for instance DLP solutions to report on hardware connections. Aside from that restrictions on what type of devices can be imported into the DC as well as ensuring a 4 eye principle can help to prevent unwanted devices to be attached to your machine.
There is also another option which I have seen used before for servers holding sensitive data, which used epoxy resin in the USB ports to prevent them from being used.
A Linux system is no more or less susceptible than any other system to a rogue keyboard attack. You'll need the same protections you'd apply to any computer.
Physically secure the computer when you're not present. Don't leave yourself logged in when you step away. Don't plug in any USB devices that you don't personally know.