Use the stable path in /dev/serial/by-id instead of ttyUSB0. It stays the same for the same device.
What the message means
Ports are numbered in the order the devices appear. Two USB serial devices can swap numbers after a reboot or a replug.
Fix it in this order
- List the folder /dev/serial/by-id and note the long name of your device.
- Use that path in your program instead of ttyUSB0.
- Or write a udev rule that creates a short fixed name from the vendor and product IDs.
- If two identical devices have no serial number, use the USB port path in /dev/serial/by-path.
- Check the group permission for the port too.
Why it happens
The kernel gives out ttyUSB and ttyACM numbers in the order the devices are detected. If two devices start at nearly the same moment, or you plug them in a different order, the numbers can swap.
The links in /dev/serial/by-id are built from information the device reports, such as its vendor, product and serial number, so they stay the same for the same device. Two identical devices that report no serial number can look alike, and then /dev/serial/by-path, which follows the physical USB port, is the stable choice.
If you see this, do this
| You see | Do this |
|---|---|
| Names swap between boots | Use by-id. |
| Two identical boards | Use by-path or a rule on the port. |
Related
serial permission denied, WSL USB port.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
Why this happens
When a USB serial adapter is plugged in, the kernel driver (for example ftdi_sio, cp210x, ch341 or cdc_acm) takes the lowest free minor number and the device appears as ttyUSB0, ttyUSB1 and so on. The number reflects the order of detection, not the identity of the hardware. Anything that changes that order, such as a hub that powers up slowly or a different plug-in sequence, can swap the names.
udev, the device manager, then adds extra symlinks built from what the device reports about itself. The by-id links use the vendor, product and serial strings. Many cheap CH340 boards report no serial string, so they may get no by-id link at all, and two identical ones cannot be told apart. In that case the by-path link, which names the physical USB port, is the stable handle.
How to confirm the cause
- Run
ls -l /dev/serial/by-idwith only one device plugged in. If your device is listed, its link name is usable in your program. If nothing is listed, the device has no usable ID strings. - Run
udevadm info -a -n /dev/ttyUSB0and look for the idVendor, idProduct and serial attributes of the parent USB device. A serial attribute that is empty or missing means a rule cannot match on it. - Run
dmesg | tail -n 20right after plugging in and read which ttyUSB number each device received. Repeat after a reboot and compare. - Run
ls -l /dev/serial/by-pathand note which link points at which port. Move the cable to another socket and see that the link name changes with the socket.
Worked example
A rule saved as /etc/udev/rules.d/99-robot.rules that gives one adapter a fixed name. Replace the example IDs with the values printed by your own device.
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A50285BI", SYMLINK+="robot_base", GROUP="dialout", MODE="0660"
# then reload the rules and re-plug the device
sudo udevadm control --reload-rules
sudo udevadm trigger
ls -l /dev/robot_baseCommon mistakes
- Using a single = where the rule needs == for a match, so the rule silently matches nothing.
- Writing a rule for two identical adapters that match on vendor and product only, so both want the same symlink name.
- Forgetting to reload the rules or to unplug and replug the device after editing the file.
- Saving the file without the .rules ending or outside the rules.d folder.
- Fixing the name but not the permission, so the program still gets permission denied.
If this did not fix it
- The user is not in the dialout group (or uucp on some distributions), so the port exists but cannot be opened.
- A service such as ModemManager or brltty grabs the port when it appears; check whether it is running.
- A charge-only cable or a loose connector makes the device vanish and return, which looks like a name change.
- The program still has the old ttyUSB name written in a config file or launch file.