Serial port terminal > Cannot open /dev/ttyS0: Permission denied
I had Windows XP on this box and it failed. Thinking it was corrupted OS I tried to reinstall, and it failed. But then I tried to install Ubuntu, and I could not run it from the USB or from the HD. Did the mem test and found out one of my 512MB sticks (had 2) failed. I removed the bad one and was able to install Ubuntu but it was sluggish. I was trying to quickly setup my packet radio for Hurricane Sandy. Downloaded the Serial Port Terminal and was able to get some use but the system kept locking up. So Installed Xubuntu next to it, planning on running out the next day to get RAM for the box. Put Xubuntu on and now I am getting the following error with serial port terminal.:
Cannot open /dev/ttyS0: Permission denied
I would like to be able to use serial port terminal, or equivalent with Xubuntu so I can use my kpc3 packet terminal, connect to the com port on the back of my computer. Any ideas?
10 Answers 10
The tty devices belong to the «dialout» group, I suspect you are not a member of this group and hence are denied access to /dev/ttyS0, so you need to add yourself to that group.
First check if you are a member of that group:
..this will list all the groups you belong to. If you don’t belong to the dialout grup then add yourself to it, for example:
sudo gpasswd --add $ dialout
You then need to log out and log back in again for it to be effective. Then see if it fixes your problem.
Even being in dialout group user with id 1000 can’t open serial port to read. After reboot. But, when I use sudo for the same executable, then it able to open /dev/ttyS0 . What the possible reason?
@Orient I had the same problem and it was because the group dialout wasn’t defined. Running newgrp dialout fixed the problem.
@TheGr8_Nik Thanks. Your solution worked on Ubuntu 16.04. No reboot involved. By default, this system did not have the group name dialout ; checked via groups command. Even after appending username to the dialout group via command sudo usermod -a username -G dialout . After using newgrp dialout , this command esptool.py -p /dev/ttyUSB0 flash_id worked.
I believe that most graphical environments have a graphical utility to do this, if you’re not comfortable with the command line. Look for it in the menu. +1 for the group name to add myself to. (Lubuntu 20.04 LTS)
The only solution that works for me is to: (every time I boot the machine)
It really needs to be fixed at time of installation. I’m on 15.10 and have tried 16.04 LTS, still the same there. Seems like such a simple fix.
The older versions 10.04LTS did not have this problem.
On Ubuntu 18.04, I fixed this issue with the following commands:
sudo usermod -a -G tty $USER sudo usermod -a -G dialout $USER
And after this, reboot.
If you still have issues, try to debug with:
And look for «denied» in the strace.
You can just use this command:
sudo adduser $USER dialout
This will add the current user to the dialout group. Login and out it to take effect.
Had a look around various forums and it looks to be a bug related to permissions. Here’s how I got around the problem (long version). You WILL need BOTH cu and setserial packages installed.
In three terminal tabs, monitored output from # tail -f /var/log/messages That’s how we know if we have a /dev/ttyUSB0 or not.
In the second tab, simply ran a loop to ls -l this device to see it’s permissions and it’s group ID is ‘dialout’. THIS is the critical bit. For some reason, your user MUST use this GID to do the cu , so.
In the third tab, as root, did # newgrp dialout (to correspond with the GID of dialout). Tested with # touch /tmp/anything . doing ls -l on this file shows it is created by root with a dialout group, so we’re ready to . # cu -l /dev/ttyUSB0 In my case I needed to hit return again to see the expected prompt, in other cases speed may need to be specified.
This was the actual piece that helped me: For some reason, your user MUST use this GID to do the cu, so. . Thanks a million.
I had just updated my operating system to Ubuntu 18. normally I would install arduino IDE through the Arduino web sight because the one provided via Ubuntu Software portal was always an older version, and I wanted the newest features and board support. However, since I just installed the newest operating system, I figured that the official software center from ubuntu would have the newest version of the IDE listed, and it did.
Now to the juicy part! Both my laptop and my desktop had the same problems accessing the serial ports. i had done the make user part of the dial-up group, and set permissions for the serial port, but always had to log out then back in, do it all again every time i rebooted! NOT FUN!.
This time, it didn’t work. Even in the software center the permissions option for the software shows the serial port «disconnected». no option to allow permission to the port even after all the permissions were granted manually through the terminal window using sudo.
I decided to uninstall the Arduino IDE from the software center, and install it from the web sight, so i did. This time I read the install files, just to see if it mentions permissions for the serial port or not, *****of course it did! ****** all the ports are set with full access permissions, user access across the board. Turns out this was the answer. after running the arduino-linux-setup.sh file provided by arduino, all serial port problems were solved. the following is an excerpt from the arduino-linux-setup.sh file;
echo "" echo "******* Add User to dialout,tty, uucp, plugdev groups *******" echo "" sudo usermod -a -G tty $1 sudo usermod -a -G dialout $1 sudo usermod -a -G uucp $1 sudo groupadd plugdev sudo usermod -a -G plugdev $1 acmrules ()
so you see even the KERNEL is effected. My suggestion:
install from the arduino ide web site. ignore the software center at this time, until it is repaired. Yes the SOFTWARE CENTER is not allowing permmisions to the serial port during install, and forever after.
How do I allow a non-default user to use serial device ttyUSB0?
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.
7 Answers 7
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?
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.
For sessions of a user that was automatically logged in, you need to reboot the computer, not just to re-login to X Window System. Observed with Ubuntu 19.04.
sudoedit /etc/udev/rules.d/50-myusb.rules
KERNEL=="ttyUSB1*",MODE="0666" KERNEL=="ttyACM6*",MODE="0666"
Unplug the device and replug it, and it should be read/write from any user!
Depending on which filesystem stores your /etc/udev, and which version of udev you have, you might indeed need to reload explicitly. But on most machines I’ve used, udev seems to figure it out automatically (using inotify).
That’s really not how it’s supposed to be done. USB serial devices should belong to the dialout group or similar, and the user should be added to that. What you are proposing would make sense for other types of USB devices however
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=="ttyUSB2*",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.
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.
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:
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.
Configure permissions for /dev/ttyUSB0
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?
1 Answer 1
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.rules 1 :
KERNEL=="ttyUSB1*", TAG+="udev-acl", TAG+="uaccess"
( 1 Yes, 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=="ttyUSB6*", OWNER="YourUsername" or: KERNEL=="ttyUSB1*", GROUP="users", MODE="0660" or: KERNEL=="ttyUSB4*", 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