esp8266 / source-code-examples

Examples of code for the ESP8266
275 stars 127 forks source link

Cannot open /dev/ttyUSB0: Permission denied #26

Open Navis-Raven opened 7 years ago

Navis-Raven commented 7 years ago

I had an issue , while trying to do flash Cannot open /dev/ttyUSB0: Permission denied

https://bugs.launchpad.net/ubuntu/+source/gtkterm/+bug/949597

I palliated to this problem with the command " sudo chmod -R 777 /dev/ttyUSB0 " each time I wanted to flash.

Do you know more about these bugs ? This maybe due to an ubuntu bug (Ubuntu 16 LTS) but I don't know

ConstantJoe commented 7 years ago

I'm not a dev on this project, just a user so if anyone else wants to jump in please do:

This is not an issue with the esp8266, and its not actually a bug at all, its just part of Linux. Its best practice to not change permissions in /dev unless as a last resort. What you want to do instead is to add yourself to the group which would give you permission to access the tty ports.

To see the groups you are in simply type:

groups

To see all available groups type:

compgen -g

Most of them are self-explanatory, in this case you want to add yourself to either the tty group, or dialout, which you would do by:

sudo usermod -a -G tty yourname

Then your user should have access to tty without use of sudo.

stefanofiorentino commented 6 years ago

After the sudo usermod -a -G tty yourname you have to logout/login to get group addition happens.

kbhuinfo commented 5 years ago

I had to add my user to group "dialout" too (ubuntu). Logout/login required.

bumbalu commented 5 years ago

Thank you people, it helped me to get access to my 3d printer from Klipper on Raspberry Pi!

abstract17 commented 5 years ago

PROPER LOGOUT IS REQUIRED

Taudris commented 5 years ago

Can this issue be added to the install documentation? Or even better, is there a way to automate handling it?

shamo1 commented 4 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

fr3kz commented 4 years ago

thank you shamo1, it helped me

Vince55 commented 4 years ago

thanks shamo1, that worked for me too!

tdgi commented 4 years ago

I add myself to dialout group and it works: sudo usermod -a -G dialout your_user_name

BlagoD commented 4 years ago

I had to add my user to group "dialout" too (ubuntu). Logout/login required.

Indeed, without being member of the "dialout" group, the access to the ttyUSB is not granted. Thanks for pointing it out!

m-atoms commented 4 years ago

note for future users who are curious about this

Problem Cannot open /dev/ttyUSB0: Permission denied error is caused by the user not having access to the serial ports as other commenters have mentioned. More specifically, the user is not in the dialout group.

Solution sudo usermod -a -G dialout $USER

For anyone who likes knowing what they're running before they run it: usermod - modify a user account -a - add the user to supplementary groups -G - a list of supplementary groups (man page says to use -a only with -G) dialout - group that controls access to serial ports (and other hardware too) $USER - Bash variable containing current username (not a builtin, usually automatically set env variable)

bonus notes: This is the 'linux way' to solve the problem. Adding the user to the group with permission to use the device is much safer than changing the permissions of the device itself. And as others have mentioned, make sure you log out for the changes to take effect.

thecompoundingdev commented 4 years ago

thanks @shamo1 ! I tried adding myself to tty and dialout group and it worked after logging back in... but the next day it gave same error but I was still a member of those groups. Had to add chown ttyUSB0 through root and it worked!

hashc4t commented 4 years ago

For anyone using Arch Linux, Arch has a separate user group for serial ports called uucp. To add your current user: sudo usermod -a -G uucp $USER then logout/login.

duncanhames commented 4 years ago

For anyone using Arch Linux, Arch has a separate user group for serial ports called uucp. To add your current user: sudo usermod -a -G uucp $USER then logout/login.

Thanks for that!

kaustubhKVS commented 4 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This worked better for me !! They should include this on documentation !! Thankyou @shamo1 !!!!!!

ThomasGeor commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This one worked for me with ESP32

loleg commented 3 years ago

In addition to adding my user to the tty and dialout groups on Fedora Linux 32, I also had to follow the instructions here:

On modern distros that use ConsoleKit create the file /etc/udev/rules.d/01-ttyusb.rules containing the following and then reload the udev rules and replug the Arduino device:

SUBSYSTEMS=="usb-serial", TAG+="uaccess"
DinRan commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

it's helpful ,thank you

diesilveira commented 3 years ago

thanks people!!

RicBar10 commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

thanks you, it solve the problem, you're a genius

Bill0412 commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This solves my problem, thanks!

cheng3100 commented 3 years ago

Hi ,just look at this issue and I found a better solution . Just type this commad to install a udev ruler file:

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules

This ruler file is from platformio.

And you also need to join group dialout and plugdev:

sudo usermod -a -G dialout $USER
sudo usermod -a -G plugdev $USER
stefanofiorentino commented 3 years ago

And you also need to join group dialout and plugdev:

and remember to logout/login..

MohamedYousof commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This worked for me Ubuntu 20.04

peely commented 3 years ago

note for future users who are curious about this

Problem Cannot open /dev/ttyUSB0: Permission denied error is caused by the user not having access to the serial ports as other commenters have mentioned. More specifically, the user is not in the dialout group.

Solution sudo usermod -a -G dialout $USER

For anyone who likes knowing what they're running before they run it: usermod - modify a user account -a - add the user to supplementary groups -G - a list of supplementary groups (man page says to use -a only with -G) dialout - group that controls access to serial ports (and other hardware too) $USER - Bash variable containing current username (not a builtin, usually automatically set env variable)

bonus notes: This is the 'linux way' to solve the problem. Adding the user to the group with permission to use the device is much safer than changing the permissions of the device itself. And as others have mentioned, make sure you log out for the changes to take effect.

This is the safest, cleanest and most reliable answer. Don't just go round changing ownership, make yourself a member of that devices ownership group. Thank you @m-atoms for the clear explanation.

EDIT: Even though I found the answer in the above comment, here is the official Ubuntu guide on installing the Arduino IDE, telling you to add yourself to the dialout group. https://ubuntu.com/tutorials/install-the-arduino-ide#4-the-dialout-group.

solroshan commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

Thanks for basic solution. @shamo1

sarattha commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This solve my problem completely. Thank @shamo1

morphiusmavin commented 3 years ago

I did all the above, but I still get this error:

Toolchain path: /home/dan/dev/esp/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
Toolchain version: esp-2020r3-49-gd5524c1
Compiler version: 8.4.0
Python requirements from /home/dan/dev/esp/ESP8266_RTOS_SDK/requirements.txt are satisfied.
App "hello-world" version: v3.4-28-g08e225dd
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
esptool.py v2.4.0
Traceback (most recent call last):
  File "/home/dan/.local/lib/python3.6/site-packages/serial/serialposix.py", line 322, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 5] Input/output error: '/dev/ttyUSB0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dan/dev/esp/ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py", line 3034, in <module>
    _main()
  File "/home/dan/dev/esp/ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py", line 3027, in _main
    main()
  File "/home/dan/dev/esp/ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py", line 2735, in main
    esp = chip_class(args.port, initial_baud, args.trace)
  File "/home/dan/dev/esp/ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py", line 212, in __init__
    self._port = serial.serial_for_url(port)
  File "/home/dan/.local/lib/python3.6/site-packages/serial/__init__.py", line 90, in serial_for_url
    instance.open()
  File "/home/dan/.local/lib/python3.6/site-packages/serial/serialposix.py", line 325, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 5] could not open port /dev/ttyUSB0: [Errno 5] Input/output error: '/dev/ttyUSB0'
/home/dan/dev/esp/ESP8266_RTOS_SDK/components/esptool_py/Makefile.projbuild:75: recipe for target 'flash' failed
make: *** [flash] Error 1

ttyUSB0 mod_rules

I also did this: sudo chmod -R 777 /dev/ttyUSB0

morphiusmavin commented 3 years ago

It wasn't a matter of permissions, it was a bad USB port. I tried one in the front and it works now.

ChuckNorrison commented 3 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

group memberships to dialout or tty not helped here. go with chown on the file from root solved it for me.

Er200096 commented 2 years ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

Legend!

gim96 commented 2 years ago

follow command worked for me .

sudo chown -R user_name /dev/ttyUSB0

Pwoodlock commented 2 years ago

For anyone using Arch Linux, Arch has a separate user group for serial ports called uucp. To add your current user: sudo usermod -a -G uucp $USER then logout/login.

You're a legend thanks :-) I am new to Arch so this really helped me.

HuilangChen commented 2 years ago

I also encountered this error message. However, I changed the baud rate to 115200 by adding -b 115200 and I can flash the device.

Tenvan commented 2 years ago

All-In-One command:

sudo usermod -a -G "$(stat -c "%G" /dev/ttyUSB0)" $USER

Chaitran77 commented 2 years ago

I add myself to dialout group and it works: sudo usermod -a -G dialout **your_user_name**

This is the one that worked - the trick was that I had to specifically put my actual username, not some variation of $USER. I think that doing this over SSH might be the reason why it didn't work using the environment variable for me.

cheungxi commented 2 years ago

My user have added to dialout plugde group. So minicom can get /dev/ttyUSB0 in default terminal. But when same user use tmux, minicom can't get /dev/ttyUSB0. minicom: cannot open /dev/ttyUSB0: Permission denied

davepl commented 2 years ago

sudo usermod -a -G "$(stat -c "%G" /dev/ttyUSB0)" $USER

Just a heads up, if your serial port is owned by root, as mine is, this will make your account a member of root.

evgnor86 commented 2 years ago

on Fedora add your user to dialoout group. sudo usermod -a -G dialout $USER

davepl commented 2 years ago

On Ubuntu, the tty are owned by “root”. What do you suggest there?

Thanks Dave

On Aug 5, 2022, at 10:05 PM, Evgeniy Ivanov @.***> wrote:

on Fedora add your user to dialoout group. sudo usermod -a -G dialout user_name

— Reply to this email directly, view it on GitHub https://github.com/esp8266/source-code-examples/issues/26#issuecomment-1207147857, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4HCFZBOTH4V23OQ4JYLUDVXXXAFANCNFSM4DTOUWFA. You are receiving this because you commented.

ChuckNorrison commented 2 years ago

On Ubuntu, the tty are owned by “root”. What do you suggest there? Thanks Dave On Aug 5, 2022, at 10:05 PM, Evgeniy Ivanov @.***> wrote: on Fedora add your user to dialoout group. sudo usermod -a -G dialout user_name — Reply to this email directly, view it on GitHub <#26 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4HCFZBOTH4V23OQ4JYLUDVXXXAFANCNFSM4DTOUWFA. You are receiving this because you commented.

cd /dev sudo chown username ttyUSB0

Maybe your usb device is numbered different. Worked for me.

davepl commented 2 years ago

But that’s exactly what I did in the video and you called it a hack…. So I’m confused!

From: ChuckNorrison @.> Sent: Sunday, August 7, 2022 1:12 PM To: esp8266/source-code-examples @.> Cc: David W Plummer @.>; Comment @.> Subject: Re: [esp8266/source-code-examples] Cannot open /dev/ttyUSB0: Permission denied (#26)

On Ubuntu, the tty are owned by “root”. What do you suggest there? Thanks Dave … On Aug 5, 2022, at 10:05 PM, Evgeniy Ivanov @.***> wrote: on Fedora add your user to dialoout group. sudo usermod -a -G dialout user_name — Reply to this email directly, view it on GitHub <#26 (comment) https://github.com/esp8266/source-code-examples/issues/26#issuecomment-1207147857 >, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4HCFZBOTH4V23OQ4JYLUDVXXXAFANCNFSM4DTOUWFA. You are receiving this because you commented.

cd /dev sudo chown username ttyUSB0

Maybe your usb device is numbered different. Worked for me.

— Reply to this email directly, view it on GitHub https://github.com/esp8266/source-code-examples/issues/26#issuecomment-1207477085 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4HCF3NFJFSJQ573NUKWKLVYAJ7NANCNFSM4DTOUWFA . You are receiving this because you commented. https://github.com/notifications/beacon/AA4HCF4DXSLFBEMC2DN7E3TVYAJ7NA5CNFSM4DTOUWFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOI74KGXI.gif Message ID: @. @.> >

inflex commented 1 year ago

I did all the above, but I still get this error:

...

I also did this: sudo chmod -R 777 /dev/ttyUSB0

On ubuntu the problem here is likely that brltty is stealing it. Try "apt remove brltty"

djusHa commented 1 year ago

On ubuntu the problem here is likely that brltty is stealing it. Try "apt remove brltty"

Perfekt, man! That was my Issue on Xubuntu. Thanks!

keemcn commented 1 year ago

On the off chance anyone is running into this issue on NixOS, the solution is to add your $USER to the tty and dialout groups in /etc/nixos/configuration.nix like this:

  users.users.$USER = {
    ...
    extraGroups = [
      "networkmanager"
      "wheel"
      "tty"
      "dialout"
    ];
  };

Followed by running sudo nixos-rebuild switch and a reboot.

Emirhan-KURU commented 10 months ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

It solved my problem, thanks, but I have to rewrite the code every time I remove and plug in the TTL converter. Is there a way I can fix it in one go?

mbuguadouglas commented 10 months ago

this is actually a permission problem u have to allow your Arduino IDE to access the specified port just simply type following commands in your terminal

sudo su //type your password cd / cd dev chown username ttyUSB0

This one worked for me on fedora linux with a nodeMCU esp8266

dukora53 commented 3 months ago

Thank you, shamo1 in Debian12 and ArduinoIDE2.2.3 it works right away.