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!

up vote 35 down vote accepted

As you've noticed, the /dev/ttyUSB0 device has the group of dialout. All you need to do is add the second user to the dialout group:

sudo adduser second_user dialout

second_user will need to log out & log back in again for this to take effect.

  • Thanks Jeremy! Does this work also for ssh access? Because when I access the pc via ssh I see two users with the same name. I suppose that one is the local user and the other the ssh one. How can I give the ownership to the ssh user? – Maverik Mar 14 '12 at 15:44
  • 1
    This will allow second_user to access the serial port from any login, ssh or local. You don't need to assign ownership to a particular login of that user. – Jeremy Kerr Mar 15 '12 at 1:01
  • 2
    Yes, you are right. I had to logout and then login again to have the access vis ssh. – Maverik Mar 15 '12 at 7:43

The easy way:

sudoedit /etc/udev/rules.d/50-myusb.rules

Save this text:

KERNEL=="ttyUSB[0-9]*",MODE="0666"
KERNEL=="ttyACM[0-9]*",MODE="0666"

Unplug the device and replug it, and it should be read/write from any user!

  • Works in 14.04 for home-made device in ttyACM socket. Thanks. +1 – NonStandardModel May 10 '16 at 18:35
  • Works like a charm. Thanks – ahaw Jun 21 '17 at 17:19

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:

KERNEL=="ttyUSB[0-9]*",NAME="tts/USB%n",SYMLINK+="%k",GROUP="uucp",MODE="0666"

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.

  • 1
    This worked for me, that is, I used the udev rules, but I changed the syntax to match my own case. linux.m2osw.com/sane-cannot-find-any-scanners -- note that if you use MODE="0666" then you probably don't need the GROUP. Only one or the other would be useful. – Alexis Wilke Mar 11 '14 at 3:18

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:

ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1 but nothing. 

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:

ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001"

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:

GROUP="whatever", MODE="0660"

then only people in group 'whatever' will get write access.

John Bowler

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.