Unable to open serial port when not super user

Asked by lu333031

I have ubuntu 7.10 (Gutsy) on a 32-bit machine. My application communicates via serial ports with other attached devices. I am the lone and superuser on this machine and have had no trouble communicating via the serial ports. However, the application needs to be usable by ordinary users. So, I created a user with "sudo adduser ....". When this regular user attempts to run the application, the serial port cannot be opened and linux error 13 (permission denied) is seen. I have tried several things, including setting the uid bit (chmod 4755, chmod ug+s etc.) on the application and modifying euid inside the program before opening the port (seteuid()) but it does not work on ubuntu. I have sample code for this issue on a thread on the ubuntu forums at -

http://ubuntuforums.org/showthread.php?t=1048553

What do I need to do in the code to enable a regular user to access privileged resources like serial ports (/dev/ttyS0) via the application?

All help will be greatly appreciated.

Thank you.

lu

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
marcobra (Marco Braida)
Solved:
Last query:
Last reply:
Revision history for this message
nhasian (nhasian) said :
#1

if a particular applications needs super user privileges, you can add it to the sudoers with the command:

sudo visudo

for example, i wanted truecrypt be able to mount/dismount without requiring a superuser password so i appended the line:

nhasian localhost=NOPASSWD : /usr/bin/truecrypt

Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#2

Make login with the user created

Please copy and paste here the result of the terminal command...

id

and please also copy and paste here the result of:

ls -la /dev/ttyS*

Thank you

Revision history for this message
lu333031 (vee-gee) said :
#3

Thank you for your input. I have no success so far in running "myapp" as user1 (same error on open()).

nhasian, I added the following in the file after visudo and it did not work -

%users ALL=NOPASSWD: /usr/local/bin/myapp

The user (user1) was added to users with
"sudo adduser user1 users"
(cmd was successful)

myapp was copied to /usr/local/bin and shows up in user1's path, i.e.
"type myapp" shows /usr/local/bin/myapp

marcobra,

"id" shows
uid=1001(user1) gid=1001(user1) groups=1001(user1) on one machine
and shows
uid=1001(user1) gid=1001(user1) groups=100(users), 1001(user1) on another machine

(I created user1 on both machine in the same manner, as far as I recall and added user1 to users group)

"ls -la /dev/ttyS*" shows -
crw-rw---- 1 root dialout 4, 64 2009-01-26 17:00 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 2009-01-26 08:56 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 2009-01-26 08:56 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 2009-01-26 08:56 /dev/ttyS3

Thank you.

lu

Revision history for this message
Best marcobra (Marco Braida) (marcobra) said :
#4

Please try to add your user to dialout group from terminal type:

sudo adduser your_username dialout

Hope this helps

Revision history for this message
lu333031 (vee-gee) said :
#5

marcobra,

You are God! :)

Your suggestion pointed me to a whole new area and I have been able to enable all new users to use my application without having to give the command from the command line for individual users.

Thank you very much.

lu (atheist ;-))

Revision history for this message
lu333031 (vee-gee) said :
#6

Thanks marcobra, that solved my question.