2

I want the change the permissions of /dev/ttyACM0 from a script.

I have tried this command:

su -c "chmod -R 777 /dev/ttyACM*" -m "$user".

When I execute the script it is asking for a password. I want run this without being prompted for password.

I tried adding an user in /etc/sudoers, but it doesn't work.

It is a CGI script. It is not working external requests (i.e. from other IPs).

user ALL= (user)  NOPASSWD: /usr/lib/cgi-bin/test.cgi

How can I do change the permissions so that anyone can execute the script from other IP addresses?

kos
  • 41,268

1 Answers1

0

You haven't said why the sudo solution doesn't work, but troubleshooting sudo is rather onerous. This test line in /etc/sudoers worked for me

cgiuser ALL = (root) NOPASSWD: /bin/chmod -R 777 /tmp/xxx*

so give it a try. Your /etc/sudoers line would be

user ALL = (root) NOPASSWD: /bin/chmod -R 777 /dev/ttyACM*

and your script would have

/usr/bin/sudo /bin/chmod -R 777 /dev/ttyACM*

Just make sure that the script runs as user, for a cgi script it's probably apache or www-data.

PS: The previous answer is just wrong. Provided that you belong to the sudo group or otherwise have the privileges, sudo su - works perfectly to become root, even if no root password is set. sudo -s is probably better, however. YMMV

nortally
  • 161