title: Access GPIO (/sys/class/gpio) as non-root
body: <p>The <code>/sys/class/gpio</code> can only be accessed as <code>root</code> by default. So I like that a new group <code>gpio</code> can use the files and directories under <code>/sys/class/gpio</code>. To achieve that I added the following lines to <code>/etc/rc.local</code> (I'm on Debian):</p>
  <pre><code>sudo chown root:gpio /sys/class/gpio/unexport /sys/class/gpio/export
  sudo chmod 220 /sys/class/gpio/unexport /sys/class/gpio/export
  </code></pre>
  <p>So this gives write permissions to all the <code>gpio</code> group members. So they can now <code>export</code> and <code>unexport</code> pins fine.</p>
  <p>The problem is they can't read/write the specific pin files after <code>export</code> (e.x. <code>/sys/class/gpio/gpio17</code>) beacause those are owned by <code>root:root</code> again.</p>
  <p>How can I change that they are created by default as <code>root:gpio</code> too? I mean I can do that manually each time I export a pin. But that's a bit uncomfy.</p>
  <p><strong>UPDATE</strong></p>
  <p>According to larsks' answer I created the missing rule file. Now it partially works:</p>
  <pre><code>-rwxrwx---  1 root gpio 4096 Jun 19 16:48 export
  lrwxrwxrwx  1 root gpio    0 Jun 19 16:51 gpio17 -&gt; ../../devices/soc/3f200000.gpio/gpio/gpio17
  lrwxrwxrwx  1 root gpio    0 Jun 19 16:45 gpiochip0 -&gt; ../../devices/soc/3f200000.gpio/gpio/gpiochip0
  -rwxrwx---  1 root gpio 4096 Jun 19 16:45 unexport
  </code></pre>
  <p>But for the <code>./gpio17/</code> I still get <code>root:root</code>:</p>
  <pre><code>-rw-r--r-- 1 root root 4096 Jun 19 16:52 active_low
  lrwxrwxrwx 1 root root    0 Jun 19 16:52 device -&gt; ../../../3f200000.gpio
  -rw-r--r-- 1 root root 4096 Jun 19 16:52 direction
  -rw-r--r-- 1 root root 4096 Jun 19 16:52 edge
  drwxr-xr-x 2 root root    0 Jun 19 16:52 power
  lrwxrwxrwx 1 root root    0 Jun 19 16:52 subsystem -&gt; ../../../../../class/gpio
  -rw-r--r-- 1 root root 4096 Jun 19 16:52 uevent
  -rw-r--r-- 1 root root 4096 Jun 19 16:52 value
  </code></pre>
  <p><strong>UPDATE 2</strong></p>
  <p>Okay I solved the problem. Because I installed Raspbian over the RaspbianInstaller I never went through the <code>raspi-config</code> tool. This seems to be a problem. Because I was also missing the <code>/sys/device/virtual/gpio/</code> folder.</p>
  <p>I followed this guide here: <a href="https://community.element14.com/products/raspberry-pi/f/forum/26425/piface-digital-2---setup-and-use#139528" rel="nofollow noreferrer">https://community.element14.com/products/raspberry-pi/f/forum/26425/piface-digital-2---setup-and-use#139528</a></p>
  <p>And afterwards the permissions were correct (even for the pin-folders and their files <code>value</code>, <code>direction</code>, ...).</p>