1

I've got a USB GPIO electronic gizmo attached to a desktop PC running Linux Mint 17 "Mate"; in this environment the gizmo appears as /dev/ttyACM0. I've written a GUI Python 2.7/Tkinter program to control the gizmo via the pySerial module. The program works when run from the console using sudo.

Being a GUI program, I want to be able to run it from the "Mate" desktop - but I can't, because being a serial device, accessing the gizmo requires root privileges obtained via sudo, wot has to be invoked at a Terminal.

# here's the offending code
import serial
numa = serial.Serial("/dev/ttyACM0", 19200, timeout=1)
....

How do I invoke the "Enter your password..." routine from within the Python program so a raw user doesn't have to open a Terminal to enter the password?

Thanks for any advice you can provide!

2 Answers 2

1

I can't answer your question, but instead I'm going to solve your problem.

When you list the device file, you'll see something like this:

$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Apr  4 11:22 /dev/ttyACM0

Both the owner (root) and the owner group (dialout) have read-write-access (rw-), while everybody else isn't able to access the device (---). Therefore, instead of giving the program root access to your system, you can simply add the user(s) to the dialout group:

$ sudo usermod -aG dialout <username>

Logging out and back in will be necessary, but afterwards your script will be able to both read and write to the serial interface without the need of a root password.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for taking the time to answer, Finwood; your solution worked well. I do wonder about security: in order to gain simple access to one device (a USB GPIO module) this solution removes the stricture that comes with accessing serial devices in general.
Yes, this enables general access to serial devices. But is it really a security issue?
1

Use gksudo rather than sudo

from subprocess import call
call('gksudo -D "Program requires root priveledge \nSudo "your command here",shell=True)

for example:

call('gksudo -D "Override Sudo message " cp /etc/hosts /home/new.hosts',shell=True)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.