I am running Ubuntu Server 20.04.02 LTS in my RPi 4b. I ran into the problem that I couldn't access the GPIO without sudo/root with my python scripts so I changed the /dev/gpiomem group ownership to my user's groups with

sudo chown root:$USER /dev/gpiomem

and allowed read and write access to /dev/gpiomem with

sudo chmod g+rw /dev/gpiomem

which solved the problem. However once I reboot these changes somehow get undone and I have to redo them in order to run my code without root access. Can someone help me with this? Thanks!

  • As this is a GPIO issue it is Pi related HOWEVER saying yo followed something is not going to get you an answer. Include what YOU DID in your question, and the permissions and groups on your OS.
    – Milliways
    Apr 28, 2021 at 6:31
  • Oh okay, thanks for the info. I added what I did in the post now. But I don't really know about the groups (I'm VERY new to this). I don't really know what would be relevant as additional information here. Apr 28, 2021 at 9:17
  • The "files" in /dev aren't real files. They only exist in memory, which is to say, when the system is running. When you (re)boot, the kernel creates them appropriately (we hope). So you have to automate the change you want.
    – goldilocks
    May 28, 2021 at 16:14

2 Answers 2


The correct solution is probably to add your user to the group which is allowed to access /dev/gpiomem

$ ls -l /dev/gpiomem
crw-rw---- 1 root gpio 246, 0 Apr 28 13:17 /dev/gpiomem

On Raspbian it is gpio.

Hopefully it is similar on Ubuntu.

Then add your user to that group.

Assuming the Ubuntu equivalent to Raspbian's gpio is ubuntu-gpio do the following command.

sudo adduser pi ubuntu-gpio

Note you have to log out afterwards and log back in for the group change to take effect.

If that doesn't make sense please edit your question and include the output of the ls -l /dev/gpiomem command.


You really haven't provided enough information to make any reasonable deduction. In particular you haven't said what the permissions of /dev/gpiomem are.

Changing permissions on a /dev/ doesn't change anything for future boots. This needs to be set in kernel or Device Tree

I am not familiar with Ubuntu Server, while I have been a Ubuntu user for 20 years, their Pi implementation uses their own kernel which has limitations compared to the Foundation implementation and while the last Server I tried works OK it is a resource hog so I have given up and just use Raspberry Pi OS - which works and strangely is well adapted to the Pi hardware.

It would seem to be unusual for a Server to implement GPIO access. At least they do seem to have implemented /dev/gpiomem (which has been in Raspbian since 2015) but not set permissions to make it usable.

Raspberry Pi OS sets groups/ownership to group gpio using udev

crw-rw---- 1 root gpio 246, 0 2021-04-26 11:46 /dev/gpiomem

See http://wiringpi.com/wiringpi-update-to-2-29/ for an example which you could adapt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.