NERP - Not Exclusively Raspberry Pi Message Board › Non-root access to GPIO hardware
This is the tool I mentioned last night, that allows you to interface with hardware as a non-root user.
You can download the source and compile it yourself (instructions on link above), or you can add the Quick2Wire Debian repository and install it with apt-get. http://dist.quick2wir...
How it works:
* You need to have root access to install it, but once it's installed you can run your GPIO programs as your standard user.
* It adds a new linux group called 'gpio'. Any user in that group will have permission to access the pins.
* It installs a command line tool 'gpio-admin'. This has the setuid <http://en.wikipedia.o... bit set, which means the OS will run the command with root privileges, even if a non-root user uses it. Only users in the 'gpio' group are allowed to run it.
* The tool allows you to export/unexport pins by creating the /sys/devices/virtual/gpio/gpioXX directory and then gives the user permissions to read/write the files within.
The approach of using small setuid programs with elevated privileges is a typical linux/unix paradigm. If you've ever used commands like 'ping', 'traceroute', or changed your password, that's what's happening.
Example of controlling an LED, from the command line, without being root:
$ gpio-admin export 22 # Export pin 22 for usage.
$ echo out > /sys/devices/virtual/gpio/gpio22/direction # Set pin to output mode
$ echo 1 > /sys/devices/virtual/gpio/gpio22/value # LED on
$ echo 0 > /sys/devices/virtual/gpio/gpio22/value # LED off
$ gpio-admin unexport 22 # Stop using that pin
It also supports setting pull-up, pull-down resistors. For more details, run "man gpio-admin".
thanks, Joe. I tend not too care a lot about security on the Pi at the moment but I know that could come back to bite me. I started getting a nervous feeling when running a web interface as root in order to control GPIO pins. I'll have to try gpio-admin out as it looks to provide a better layer of protection for not very much effort.
Also, it's nifty that you have your own repo so the installation is even easier. Do you think you'll try to get Raspbian to add the package at some point?