Linux – Configure permissions for /dev/ttyUSB0

linuxpermissions

I'm trying to communicate with an Arduino from Ubuntu 12.04. When plugging in the USB cable, the arduino's serial port occurs as /dev/ttyUSB0. When I try to connect to it using moserial, I'm getting an "Could not open device /dev/ttyUSB0" error, but not when I launch moserial using sudo. What I have to configure to make the serial device accessible as normal non-root user?

Best Answer

You have several options:

Automatic ACL assignment

You most likely have systemd-logind or ConsoleKit running in Ubuntu, which can automatically configure ACLs on device nodes based on which user account is currenty logged in at the console. These ACLs grant access additionally to the usual permissions and can be seen using getfacl.

To use this, add the following to /etc/udev/rules.d/60-extra-acl.rules1:

KERNEL=="ttyUSB[0-9]*", TAG+="udev-acl", TAG+="uaccess"

(1Yes, create the file. It doesn't exist by default; the whole directory is for admin customizations.)

Group-based access

The tty devices are usually readable/writable by a specific group such as "dialout" or "uucp". Add yourself to that group to gain access to all serial ports:

# gpasswd -a YourUsername dialout

Don't forget to log out & log in again so that group changes get applied.

Permission or ownership changes

udev rules similar to above can also be used to set the "main" owner & group as well as the permissions (which is how the default group got set in the first place). For example:

     KERNEL=="ttyUSB[0-9]*", OWNER="YourUsername"
or:  KERNEL=="ttyUSB[0-9]*", GROUP="users", MODE="0660"
or:  KERNEL=="ttyUSB[0-9]*", MODE="0666"

You can assign to OWNER, GROUP, and MODE parameters.

Temporary manual change

To do a one-time change, just use chmod and/or chown as you normally would.

     # chown YourUsername /dev/ttyUSB0
or:  # chmod a+rw /dev/ttyUSB0
Related Question