TransWikia.com

Run application with other user than root

Raspberry Pi Asked on December 28, 2021

Within a small project I opened a wireless connection using the NRF24L01 transceiver and a Raspberry Pi 3 Model B+ with Raspbian 10. To communicate over the transceiver I make use of the RF24 library of tmrh20 (https://github.com/tmrh20/RF24.git).

In the RF24 folder is an example application called gettingstarted that has to be created using make. Also, SPI has to be enabled in Raspbian. When running the application gettingstarted I have to use sudo and for some reason it will not let me run the application with the local user.

Example of it working:

sudo ./gettingstarted

Example of it not working:

./gettingstarted

Error message:

pi@raspberrypi:~/Desktop/RF24/examples_linux $ ./gettingstarted
RF24/examples/GettingStarted/
terminate called after throwing an instance of 'std::runtime_error'
  what():  Process should run as root

What must be done to allow the local user (user "pi" in my case) to run gettingstarted?

2 Answers

You used make to create gettingstarted so I assume it is compiled to an executable file and not only a script for an interpreter (bash, python, etc.). Having this you are able to use the setuid or setgid flags on the file. This flags on file permission are used to execute the file with the rights of its owner or group and not with the permission of the executing user (user pi) by default.

Have a look at Wikipedia - setuid and find what setting is appropriate for you.

But be aware that using setuid/setgid have important security risks if the executable isn't proper designed. You will find many warnings about this on the web.

Answered by Ingo on December 28, 2021

Nope you have to run as root if you don't want to use sudo you could just do sudo bash and then run your commands. This will put you into the root user in the terminal.

Alternatively, you could create a shell script with just sudo ./gettingstarted, I don't think you will need to run sudo in front of that, but could be wrong.

There might be a way to upgrade the pi account to sudo, however, it's probably not recommended.

Answered by dinomite59 on December 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP