Ubuntu: Write to serial port: permission denied
Solution 1
If you still want to use sudo to access the port, the issue is that cat
is running with root privileges, but the redirection isn't. Try cat hello.txt | sudo tee /dev/ttyUSB0
. This uses the tee
tool, run as root. It outputs both to stdout (the terminal), and to the specified destination (in this case, the serial port).
Solution 2
By default as I recall serial ports on Ubuntu belong to the "dialout" group. You can add yourself to this group by running something like the following:
sudo gpasswd --add jodes dialout
You may need to log out and log back in before this takes effect, but after doing so you should be able to read and write from and to your serial ports including USB to serial converters.
Related videos on Youtube
CL22
Try Googling: "trolls are breaking the stack exchange system". Please... Don't be one of them. -- non facias malum ut inde fiat bonum --
Updated on September 18, 2022Comments
-
CL22 over 1 year
I've connected a USB to Serial bridge dongle, and running
dmesg | grep tty
outputted the following:[ 0.000000] console [tty0] enabled [603199.380677] usb 2-2: cp210x converter now attached to ttyUSB0
So now I'm trying to write to it as per the answer in this previous question by running the following:
cat hello.txt > /dev/ttyUSB0
and
sudo cat hello.txt > /dev/ttyUSB0
But both result in the following error:
bash: /dev/ttyUSB0: Permission denied
What am I doing wrong?
Thanks
-
user391339 about 6 yearsecho 'hello world\r\n' | sudo tee /dev/ttyUSB0 worked for me .... echo 'hello world\r\n' > sudo tee /dev/ttyUSB0 did not -- it created a file called sudo
-
user391339 about 6 yearscan someone confirm that this worked for them? it did not work for me alone for sudo echo "blabla" > /dev/ttyUSB0, but ssmy's method did.... Unfortunately I only tried ssmy's method after adding myself to the dialout group however ....