[program,arduino] Error: Permission denied: /dev/ttyACM0

Motivation Error: Permission denied: /dev/ttyACM0

/data/bin/arduino-cli compile --fqbn esp8266:esp8266:generic --port /dev/ttyACM0 --upload

When uploading to arduino, this is a common error for starters. To fix the permission, it’s best NOT to chmod or chown because the port could change to /dev/ttyACM0 or /dev/ttyUSB0 and you will have to chmod every time you have a permission problem, which looks silly.

You should reproduce the problem via:

touch /dev/ttyACM0
# touch: cannot touch '/dev/ttyUSB0': Permission denied

Solution

Observe that the port belongs to group dialout:

crw-rw---- 1 root dialout 188,  0 7月  19 16:23 /dev/ttyUSB0

This means you can simply acquire permanent permission by adding current user to dialout, just as how you gives sudo access by assgining a user to sudo group. Let’s do

sudo usermod -aG dialout $USER

After usermod, you need to re-login to make the change takes effect.

su $USER

Now you should find the port accessible, test with touch /dev/ttyACM0

Comments