schollz / raspberry-pi-turnkey

How to make a Raspberry Pi image that can be deployed anywhere and assigned to a WiFi network without SSH :ok_hand:
MIT License
832 stars 90 forks source link

You don't need `sudo` for the pi user .. #4

Closed skx closed 5 years ago

skx commented 6 years ago

As a result of fixing #2, you've switched to adding a command to /etc/rc.local. You've added:

su pi -c '/usr/bin/sudo /usr/bin/python3 /home/pi/raspberry-pi-turnkey/startup.py &'

The script rc.local will be launched as root, via the boot-up process:

You seem to be trying to do both:

schollz commented 6 years ago

Thanks. The problem is I don't want to run as root completely - just some things (like starting up hostapd, rewriting wpa configuration) - and I still want to use the paths that are specified in the /home/pi/.profile (non-root).

To get the best of both worlds, I also switched the README so that pi is in the sudoers: "Add pi to the sudoers, so that you can run sudo commands without having to be root (so that all the paths to your programs are unchanged)."

skx commented 6 years ago

If you just want to source ~pi/.profile you could run su with the -l flag..?

ptwz commented 6 years ago

Maybe you could move the parts that require root access to a different script with proper input sanitation and make it setuid root. Then call this separate script and let it do the "dirty" root work. Classic UNIX programs started out as root, bound the ports and then used setuid() to drop the privileges once ready to work

skx commented 5 years ago

Closing due to inaction, and the fact that it's a suggestion / matter of taste.