On a linux program, on the console (as in no xorg, etc), I'm using using /dev/input/event* to read keyboards and mice, however I need to be root to be able to read them. Is there an alternative form to read that stuff without needing root privileges (without having to change permisons and config files, etc)?
I understand why it does that by default no need to explain that.
yes, it's possible by creating a udev rule, see this HowTo
For example as root, create the file /etc/udev/rules.d/99-input.rules:
KERNEL=="event*", NAME="input/%k", MODE="660", GROUP="input"
Note: you will probably need to create the group "input" first.
Check to see to which group the device files belong to. For example, here I get:
$ ls -l /dev/input/ ... crw-rw---- 1 root plugdev 13, 64 Nov 4 18:01 event0 crw-rw---- 1 root plugdev 13, 65 Nov 4 18:01 event1 crw-rw---- 1 root plugdev 13, 66 Nov 4 18:01 event2 crw-rw---- 1 root plugdev 13, 67 Nov 4 18:01 event3 crw-rw---- 1 root plugdev 13, 68 Nov 4 18:01 event4 ...
The user executing your program needs to be in the plugdev group on this system. Something similar is probably the case on your system.
If you're asking for a way to circumvent that (reading or writing to the device without being in the group), then no. That would obviously defeat the purpose of security though user groups.
An alternative to reading the event devices directly would be to use an appropriate user space API instead. For example, to read the keyboard you would use ncurses, and to read the mouse you would use GPM.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.