Changing Permissions of the GPIO Directory

I wish to allow for my program to interface with the GPIO pins on the jetson TX2 during runtime. An easy solution to this problem is to start the script with sudo permissions, but this opens up the system to vulnerabilities. The next easiest solution would be to change the permissions of the /sys/class/gpio/ directory. However, this contains two issues. Firstly, these permissions do not persist on reboot (from what I have initially observed). Secondly, these permissions are not recursive to exported pins (e.g. If I were to export pin 217, I would not be able to write to its direction or value without having to grant permissions once again).

If anyone has any insight as to where to look for a solution to this, please let me know.


hello s.bourne,

you’ll need root permission to export and access via sys-nodes.
please have implementation in low-level driver to control GPIOs, suggest you also check similar discussion thread Topic 1060796 for reference.

The solution I have found for this problem is writing a custom udev rule, coupled with creating a seperate group for GPIO control. Specifically, I created a group called gpio, and gave that group access to the /sys/class/gpio directory by creating a custom udev rule. From there, you can assign your user to the gpio group, which allows for gpio access without root permissions. Below is an example of a udev rule which would achieve this.

SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", \
         PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport; chmod  220 /sys/class/gpio/export /sys/class/gpio/unexport'"
 SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", \
         PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/  value; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"