I have an Ubuntu 11.10 system with 2 users:
- The first was created during the installation
- The second instead was created after. It belongs to the sudoers group.
Now the problem is that when the second tries to use a device ttyUSB0
the following error is returned:
"Could not open serial port /dev/ttyUSB0"
I was able to fix it by using:
sudo chown :second_user /dev/ttyUSB0
However when I disconnect the device and reconnect it the problem comes back.
Is there a way to allow different users to access the devices?
I suppose I have to add the user to a specific group. Currently the owner is root
and the group is dialout
. However I'm not sure about the group and I don't know how to add the user.
Thanks!
As you've noticed, the
/dev/ttyUSB0
device has the group ofdialout
. All you need to do is add the second user to thedialout
group:second_user will need to log out & log back in again for this to take effect.
The easy way:
Save this text:
Unplug the device and replug it, and it should be read/write from any user!
You could use UDEV. It's a system that triggers every time plug or unplug a device (amongst other stuff). With it, you script various things to happen, including setting permissions.
Run
sudoedit /etc/udev/rules.d/50-ttyusb.rules
and stick this in there:Save, exit and replug and you should be up and running. Setting the permission to 666 allows anybody to write to the device.
I'm basing this off this page which is from a few years ago but something like this should work if Jeremy's solution doesn't.
Fantastic -- the UDEV solution given here was the ticket for me.
I installed Icom's CS-F3020_F5010_F5020 program via Wine, created the link for the Com port as follows:
Then I realised I needed to change permissions on /dev/ttyUSB0 to allow me to access it. That works great until you unplug/replug the USB in, then you need to re-change the permissions.
I tried adding my user to dialout group but this didn't solve the problem for some reason.
Using UDEV solves the final piece of the puzzle. Now I can program my Icom radio using Linux, plug and unplug the USB/Serial device without any more fuss. Woohoo. Thanks.
The udev rules work but as written they have the very nasty side effect of making all
ttyUSB*
devices accessible to everyone. This is not good because that may be a security risk depending on what else is on the system.Instead use a more selective udev rule. For example I have a USB device that operates a set of switches. From dmesg when it is plugged in I can see the ID of the manufacturer and the product code (plus, even, in this case, a serial number for the device). I can add:
to the kernel lines above and the rule will only apply to that device. Even better rather than assigning to the
MODE
variable alone set the group too:then only people in group '
whatever
' will get write access.John Bowler
You can also use
chmod
(I did it on Raspberry linux).In my case,
sudo adduser pi dialout
didn't work ("The user 'pi' is already a member of 'dialout'", but non root app still didn't have access to serial).See its linkage (
/dev/serial0
->/dev/ttyS0
):And update read/write permission for all users:
Now user code (e.g. 'pi' user dotnet core application) can access
/dev/serial0
.