avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied ioctl("TIOCMGET"): Inappropriate ioctl for device ioctl("TIOCMGET"): Inappropriate ioctl for device code example

Example 1: An error occurred while uploading the sketch avrdude: ser_open(): can't open device "/dev/ttyUSB0": Permission denied

sudo chmod 777 /dev/ttyUSB0

Example 2: avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied ioctl("TIOCMGET"):

# On a terminal:

#If you use Ubuntu, Debian etc...
sudo adduser <yourname> dialout

# If you user Arch Linux...
sudo gpasswd -a <yourname> dialout

#then

sudo chmod a+rw /dev/ttyACM0