Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there system functions that allow my application to have root privileges?

I have an application that runs on an embedded system that automatically runs at startup. Because some of the functionality involves reading and writing to the serial port I require the software to have root privileges. On my desktop it is no problem as I can just run the program as sudo and it is fine. On my embedded device I am unable to do this so what I was hoping is that there is some linux system function that will allow the code to not be run as root, but can have root privilege to access the serial port than it is needed. I realise that this is probably not a good idea from a security perspective but since it is on an embedded device I have no alternative.

like image 227
mathematician1975 Avatar asked Feb 02 '26 12:02

mathematician1975


1 Answers

Have you considered just changing the permissions of the serial port device node so that your application can access it?

E.g. to allow every application to access the /dev/ttyS0 serial port:

chmod a+rw /dev/ttyS0

To provide more fine-grained control, you can create a separate user group and chgrp your serial port device node:

chgrp serial /dev/ttyS0
chmod 0660 /dev/ttyS0

Afterwards, all you need is making sure that the user your application runs as is in the serial user group.

Or you could even make the application user the sole owner of the device node:

chown appuser /dev/ttyS0
chmod 0600 /dev/ttyS0

Requiring root privileges just to access a device node is not the right approach...

like image 133
thkala Avatar answered Feb 05 '26 02:02

thkala