如何修复 /dev/ttyUSB0 或 /dev/ttyACM0 权限错误
问题:
尝试连接 USB 设备时,你看到类似这样的错误
tty_permission_error.txt
[Errno 13] Permission denied: '/dev/ttyUSB0'并且无法建立 USB 连接。
解决方案
在 Debian 和 Ubuntu 上,/dev/ttyUSBx 和 /dev/ttyACMx 设备由 dialout 组拥有。因此,解决方案是将你的用户添加到 dialout 组:
add_user_to_dialout.sh
sudo usermod -a -G dialout $USER之后,你需要完全注销并重新登录(如果有疑问,请重启计算机)!
虽然你有时可以通过使用 sudo 以 root 运行你想要使用的任何命令来快速解决此问题,但这不是推荐的解决方案,因为它将允许你调用的程序完全访问整个计算机 - 而不仅仅是限于 USB 设备的访问。因此,这种方法带来重大的安全风险,此外,某些程序在使用 sudo 调用时无法正常工作。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow