4

I want to give access to serial port /dev/ttyACM0. How to execute the "sudo chmod 777 /dev/ttyACM0" command from shell script ?

N0rbert
  • 99,918
  • 1
    you mean 774 or 770? Never give 777 permissions at a folder/file, you would create a huge security breach into your OS – damadam Dec 04 '19 at 13:51
  • You create a script to run that command and run it as root. – George Udosen Dec 04 '19 at 13:51
  • If you are asking how to run that command from a shell script without being prompted for a password, see this question: https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password – Wayne Vosberg Dec 04 '19 at 13:52
  • 1
    There is no need for this: you set the dialout group to include your user. Please keep away from using 777 with chmod. 7[57][05] is for dirs, 6[64][40] is for files. You can set /tmp and cache locations to 777 but then with the sticky bit. – Rinzwind Dec 04 '19 at 14:25

1 Answers1

9

Giving 777 permission to a file is not at all recommended. Since you want to give access to the Serial port, you have to add the user to the dialout group

sudo usermod -a -G dialout <username>

Now, no permission will be asked while accessing the serial port.

Note that this solution will also work for uploading code to Arudino boards in Arduino IDE or Serial Monitor in Ubuntu.

Tejas Lotlikar
  • 2,945
  • 5
  • 17
  • 26