Evan83
Posts: 12
Joined: Mon Aug 04, 2014 5:47 pm

Problems with permissions

Wed Jul 06, 2016 5:30 pm

I'm trying to grant access for students in my research lab to run programs that access the GPIO pins without giving them sudo access. I'm using the Jessie distribution which should eliminate the need for this level of permission, but I've encountered an unexpected problem: The system won't allow the students to import certain classes from my PWM driver without sudo access! :?

Here's the error I keep receiving:

File "filename", line 17, in <module>
from Adafruit_PWM_Servo_Driver import PWM
File "/home/user/Adafruit_PWM_Servo_Driver.py", line 11, in <module>
class PWM:
File "/home/user/Adafruit_PWM_Servo_Driver.py", line 35, in PWM
general_call_i2c = AdafruitI2C(0x00)
File "/home/user/Adafruit_I2C.py", line 4, in __init__
self.bus = smbus.SMBus (busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber())
PermissionError: [Errno 13] Permission denied

I've attempted to rectify the problem by changing permissions to all the files indicated using chmod, but this did not correct things. When you run the program with sudo, this problem doesn't occur. What do I need to do to allow the users to call these particular classes without sudo access?
Thanks for your help! :)

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Problems with permissions

Wed Jul 06, 2016 5:34 pm

I think what you need to do is to add your students to a group (student-staff, or staff) that has permissions to the /dev/gpiomem , or to /dev/mem (although the former is I think all you need, if not someone will correct me)

marcus
marcus
:ugeek:

Evan83
Posts: 12
Joined: Mon Aug 04, 2014 5:47 pm

Re: Problems with permissions

Wed Jul 06, 2016 7:02 pm

Marcus,

That didn't do the trick. :( But there may be something I'm doing incorrectly.
I created a new group using addgroup - worked
Gave the new group permission to access /dev/gpiomem - worked
Tried giving the new group permission to access /dev/mem - when I type ls -l /dev/mem the new group is not listed.

Run the program, still get the permission error.

Romonga
Posts: 123
Joined: Mon May 09, 2016 7:09 pm
Location: Montgomery Il

Re: Problems with permissions

Wed Jul 06, 2016 7:24 pm

Try adding the group gpio and dialout to the user
You can run, but you will only die tired.

Evan83
Posts: 12
Joined: Mon Aug 04, 2014 5:47 pm

Re: Problems with permissions

Wed Jul 06, 2016 7:36 pm

Romonga wrote:Try adding the group gpio and dialout to the user
Currently my username is a member of the following groups: evan (username), dialout, i2c, gpio, and students (group created and given read, write, execute permission for /dev/gpiomem). Adding to the group dialout did not solve the problem.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Problems with permissions

Wed Jul 06, 2016 8:12 pm

Evan83 wrote:
Romonga wrote:Try adding the group gpio and dialout to the user
Currently my username is a member of the following groups: evan (username), dialout, i2c, gpio, and students (group created and given read, write, execute permission for /dev/gpiomem). Adding to the group dialout did not solve the problem.
This is soooo frustrating. ... seems that one thing works for some, but not everyone.

... well, hang out, sooner or later someone will figure this out (then I'm going to document the snot out of it) !

marcus
marcus
:ugeek:

User avatar
DougieLawson
Posts: 35533
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Problems with permissions

Thu Jul 07, 2016 12:02 pm

MarkHaysHarris777 wrote:I think what you need to do is to add your students to a group (student-staff, or staff) that has permissions to the /dev/gpiomem , or to /dev/mem (although the former is I think all you need, if not someone will correct me)

marcus
/dev/gpiomem has owner=root group=gpio.

Code: Select all

[email protected]:/dev # ls -la gpio*
crw-rw---- 1 root gpio 244, 0 Jan  1  1970 gpiomem
[email protected]:/dev #
that's set in /etc/udev/rules.d/99-com.rules

Any group changes needs a user to logout and login again. Any changes to udev rules are easiest to implement with a reboot.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Evan83
Posts: 12
Joined: Mon Aug 04, 2014 5:47 pm

Re: Problems with permissions

Thu Jul 07, 2016 6:00 pm

Just wanted to follow up here and inform all interested parties that I've managed to get things working as intended.

Dougie: You were dead on. Rebooting after changing permissions is right up there with "is it plugged in?" That was part of my problem. I feel like a total dope now! (Note to self, reboot before posting...)

Romonga: Your solution was mostly correct. I only needed to add my username to the groups 'gpio' and 'i2c' to get things to work. I did some troubleshooting and it did require membership to both groups to get things to work properly. I've tested this with one of my student usernames (has no sudo permissions) and this worked for them as well. Just to be on the safe side, I've added everyone to 'dialout'.

Thank you all for your help and replies! :D

Return to “Troubleshooting”