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
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?
setuidfrom 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.