I would like to write to a Device File (of a printer) located at /dev/usb/lp0
. The file is owned by lp
user and group. This file is created whenever I connect my printer device to the system.
I tried adding myself to the lp
group. However the lp0
file doesn't appear when the printer is connected. Removing myself from the group fixes the issue.
One solution to get write permission is to -
- Detect whenever the device is connected
- Trigger a shell script that runs
sudo chmod 0666 /dev/usb/lp0
This led me to the answer at https://unix.stackexchange.com/a/28711
The shell script is successfully triggered but it doesn't run the sudo command
*, since the shell script was not executed from the terminal. I have tried using sudo
and gksudo
, both have failed to prompt me to enter password i.e, I am unable to escalate permissions through a background shell script.
What I have tried?
setuid
from Unix & Linux @ StackExchange, but it seems to be a very bad idea.echo 'my_insecure_password' | sudo -S command
, it didn't work*.
I did not try Polkit
, which was suggested in other answers, due to the level of its complexity. But I am willing to go for it with proper directions.
/dev/usb/lp0
is added when the printer is plugged in, but not if you are in grouplp
. Is this correct understanding? As it seems odd. – ctrl-alt-delor Jul 09 '16 at 21:15