Page 1 of 1

Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 3:33 pm
by tftdrd60
I am getting some success with the Rpi and want to get my application to run automatically at startup.

I wonder if there is a way to permanently assign sudo rights to pi so the program works without me having to go into terminal?

It's this 'no access to /dev/mem' bit that's bugging me... I've got it to work using sudo python test2.py but surely there is a way to configure pi to have admin rights at start up.

Thank you

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 4:04 pm
by joan
sudo is normally configured by default to give the pi user superuser rights.

Why do you think you can't launch an application at start-up?

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 4:07 pm
by DougieLawson
If you move the pi userid to UID(0) and GID(0) it becomes a root id.

Or assign a password to root with sudo passwd, lock or delete pi and just login as root every time.

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 5:39 pm
by raspfakehuman
Set suid on the program? If it is just for setup, do suid for setup only.

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 9:56 pm
by hippy
I'm having the same problem trying to run a python script when logged in as "pi". The program imports RPi.GPIO to access the GPIO pins. Run with sudo it works as expected but no joy in getting it to run using a simple ./blink.py

Tried every combination of chown and setting SUID but still no joy ...

pi@raspberrypi:~$ ls -l blink.py
-rwsr-sr-x 1 root root 312 Oct 1 21:32 blink.py

pi@raspberrypi:~$ ./blink.py
Traceback (most recent call last):
File "./blink.py", line 7, in <module>
GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!

Is the problem that python itself doesn't have superuser execution rights ?

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 10:09 pm
by DirkS
Is the problem that python itself doesn't have superuser execution rights ?
Correct. You are actually not running the .py script, but the python program itself where the script is just an input file. So setting suid on the script has no effect at all.

Gr.
Dirk.

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 10:13 pm
by DougieLawson
DirkS wrote:Correct. You are actually not running the .py script, but the python program itself where the script is just an input file. So setting suid on the script has no effect at all.
It's a horrible security exposure but you could make /usr/bin/python a suid program.

Re: Can I configure user pi to have superuser rights?

Posted: Wed Oct 01, 2014 11:20 pm
by hippy
Thanks. In my case the desire was simply to save on typing so the easiest solution seems to be to create a ./blink.sh and run that. That can have sudo python blink.py in it which retains maximum security elsewhere and avoids having to uses chown/chmod.

Re: Can I configure user pi to have superuser rights?

Posted: Thu Oct 02, 2014 10:49 am
by rpdom
You could try changing the shbang line on your script to

Code: Select all

#!/usr/bin/sudo /usr/bin/python
which should make it work without doing nasty things with permissions and suid bits.

Re: Can I configure user pi to have superuser rights?

Posted: Fri Oct 03, 2014 12:47 pm
by hippy
rpdom wrote:You could try changing the shbang line on your script to

Code: Select all

#!/usr/bin/sudo /usr/bin/python
which should make it work without doing nasty things with permissions and suid bits.
Excellent - that worked perfectly.

It seems that "#!/usr/bin/sudo python" is enough.

I had searched on Google for using sudo within shebang but did not find anything useful. Tried a few things but hadn't found the magic incantation.