question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keyboard linux with no-root user, but in "input" group

See original GitHub issue

Its supposed that keyboard linux only work with root user, and this situation cant never be a solution.

I want to modify system to give access to a generic user (example pi user), to execute python from this user instead root, changing permissions…

pi@rpi4:/ $ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev lpadmin gpio i2c spi
pi@rpi4:/ $ ls -la  /dev/input/event1
crw-rw---- 1 root input 13, 65 nov 24 20:44 

As you can see, ‘pi’ user is supposed to have read and write access to /dev/input/event1, because it belongs to ‘input’ group, and /dev/input/event* files are assigned to group ‘input’, with rw access for users belonging to that group.

I have changed your code to bypass ensure_root() , but even with this, I get this error:

 python3 -m keyboard
/home/pi/.local/lib/python3.7/site-packages/keyboard/_nixkeyboard.py:110: UserWarning: Failed to create a device file using `uinput` module. Sending of events may be limited or unavailable depending on plugged-in devices.
  device = aggregate_devices('kbd')
Couldn't get a file descriptor referring to the console

Any clue?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
d4v3y0rkcommented, Feb 11, 2020

I actually figured this out. comment out the two calls to ensure_sudo() and place this content into

/etc/udev/rules.d/12-input.rules

content:

SUBSYSTEM=="input", MODE="0666" GROUP="plugdev"
SUBSYSTEM=="misc", MODE="0666" GROUP="plugdev"
SUBSYSTEM=="tty", MODE="0666" GROUP="plugdev"

I am not sure of the security implications of allowing 0666 w+r for everyone on those devices. I would think that doing that will allow anyone (in a multiuser env) to “listen” to keystrokes from other users… so be careful with this.

2reactions
linux-mancommented, Dec 8, 2021

I can run “pressed_keys.py” just fine on Linux Mint 20.2, adding tty and input groups. Just a typo, at _nixkeyboard.py line 76 warning; change “useradd” to “usermod”. Can the same be done on boppreh/mouse library?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read from /dev/input devices without root privileges
In my case, I would like to use the Python library evdev to read from multiple keyboards (so that I know which keyboard...
Read more >
How to Create a Non-root User on Your Server - HostAdvice
This guide shows you how to create a non-root user on your Ubuntu 18.04 virtual or dedicated server.
Read more >
Keyboard - Debian Wiki
To configure the keyboard for Linux kernel and X, you have to install keyboard-configuration. The package console-setup is also needed. The ...
Read more >
Linux raw input without root permission? - Stack Overflow
Note: you will probably need to create the group "input" first. ... For example, to read the keyboard you would use ncurses, and...
Read more >
Having Steam installed gives your user read-write access to ...
Ask yourself how KDEconnect/GSConnect works for mouse/keyboard emulation from your phone. But is there anything wrong with providing input- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found