I have a simple Python script that controls three LEDs. I want to limit the
sudo command for my user counter (member of group pimem) to just run this script and because it access the GPIOs also allow
/dev/mem/. I am connecting to my Pi with tigervnc.
/etc/sudoers file I added the following to the end:
#Allow group members to run scripts in dirs of counter counter ALL=(ALL) NOPASSWD: /usr/sbin/python /home/counter/Desktop/piCam.py #Allow users of group pimem to access /dev/mem %pimem ALL=(ALL) /dev/mem/
My script is this:
#!/usr/bin/env python # ./piCam.py -f 40 import RPi.GPIO as GPIO import sys import time frequency = 50 #Hz dutyCycle = 10 # 0.0 - 100.0 LED_1 = 11 LED_2 = 13 LED_3 = 15 def mainArgs(argv): if len(argv) < 2: return -1 else: for i in range(1, len(argv)): arg = argv[i] if arg == '-f': frequency = int(argv[i+1]) print("f = ", frequency) if arg == '-d': dutyCycle = int(argv[i+1]) print("d = ", dutyCycle) if __name__ == "__main__": mainArgs(sys.argv) GPIO.setmode(GPIO.BOARD) GPIO.cleanup() GPIO.setwarnings(True) GPIO.setup(LED_1, GPIO.OUT) GPIO.setup(LED_2, GPIO.OUT) GPIO.setup(LED_3, GPIO.OUT) print("Lights on") PIN_1 = GPIO.PWM(LED_1, frequency) PIN_1.start(dutyCycle) PIN_2 = GPIO.PWM(LED_2, frequency) PIN_2.start(dutyCycle) PIN_3 = GPIO.PWM(LED_3, frequency) PIN_3.start(dutyCycle) try: while True: time.sleep(5) #Wait for user to take photo except KeyboardInterrupt: print("Keyboard Interrupt") PIN_1.stop() PIN_2.stop() PIN_3.stop() GPIO.cleanup() print("Done")
But when running I get the following error:
Sorry, user counter is not allowed to execute './piCam.py' as root on PiCellCounter.
How can I run this script with
sudo but not more?