Permission denied: /dev/ttyUSB0

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Permission denied: /dev/ttyUSB0

Post by ^rooker »

[PROBLEM]
While writing a serial-to-html interface for a video A/D converter, I ran into the following problem:
My serial interface was FTDI-based, so it appears as "/dev/ttyUSB0".
Nice, but by default, the access rights for this device are like this:
crw-rw---- 1 root dialout 188, 0 2012-03-01 16:10 /dev/ttyUSB0
Even if you change the rights manually, every time you unplug/replug the device, they will be reset to this :(

Although usually, you'd just assign the user to access that device to the group "dialout", in my case I wasn't too comfortable doing so, because I'm accessing the serial device from Apache/PHP. So the user is "www-data". This means that that user would be able to access *any* device, the user "dialout" is allowed to write to. And we're talking about a WEB interface here...

[SOLUTION]
So I've decided to only grant access to /dev/ttyUSB0:

As "udev" is responsible for these access rights, you can simply create a new rule file in /etc/udev/rules.d, called "80-ttyusb.rules" (for example) - with the following content:

Code: Select all

KERNEL=="ttyUSB0", MODE="0666"
Now, unplug/replug the device and it should show up with read access for anyone:
crw-rw-rw- 1 root dialout 188, 0 2012-03-05 16:01 /dev/ttyUSB0
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply