Esphome unable to flash USB permission denied?

I’m having a difficult time getting flashing a Sonoff SV with espthe home. I’ve been able to compile and now I’m to the final part where I’m trying to flash to the device. Unfortunately I’m receiving the following error: v2.6 Serial port /dev/ttyUSB0 ERROR Running command failed: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0' ERROR Please try running --before default_reset --after hard_reset --chip esp8266 --port /dev/ttyUSB0 write_flash 0x0 config/door_garage/.pioenvs/door_garage/firmware.bin locally.

I’m running the python version under Ubuntu 19.0x. I’ve been able to flash Tasmoto firmware in the past without issue. I’ve tried using the web GUI in addition to the CLI with similar results. Any help would be appreciated. Thanks!

What is ownership and permissions of /dev/ttyUSB0?

ls -l /dev/ttyUSB0

What groups is the user who is running esphome a member of

id username

Check to see if your user is a member of the dialout group:

[email protected]:~$ groups
cariboo adm dialout cdrom sudo dip plugdev lxd lpadmin sambashare

If not add your user:

usermod -a -G  dialout your-username

I checked and the user was not part of the group. I’ve since added it, but I’m still receiving the same error.

Ownership of the USB shows:

crw-rw---- 1 root dialout 188, 0 Jul 20 10:36 /dev/ttyUSB0

the user that’s logged in is part of the following groups:


Anyone have any other thoughts? My next attempt will be to run everything through docker, but it would be great if I could avoid that.

Have you tried using the gui?

you’ll have to refresh the environment for the user/process that is trying to access the usb port, some versions of linux may require a full reboot, others logging out and back in, some can refresh it on the go, but I can’t remember the command atm.

I’ve tried both the GUI and CLI with the exact same results. :frowning:

I’ve turned the laptop off and restarted twice since running into this issue. Nothing seems to make any difference.

Specifically after usermod -a -G dialout your-username?

And you are sure both CLI and GUI is running as the same username? Do you have SELinux enabled?

If you’re fed up you could always do sudo chmod 666 /dev/ttyUSB0 then flash your device and restore the permissions back sudo chmod 660 /dev/ttyUSB0 (that change will not persist across reboot even if you don’t revert it).

Also check if another process is using the serial port. f.ex.

$ sudo lsof | grep ttyUSB
esphome   25576                  beikeland    3u      CHR              188,0      0t0        477 /dev/ttyUSB0

When I try to run that command I receive the following error

lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete.

Are you sure diode is the user running esphome?

thats probably okay, for good measure try without the | grep ttyUSB and see that you do get a long list of all the open files on your system. we’re not interested in any fuse based files in any case. and as such no other output should indicate the file/serial port isn’t in use. (grep ttyUSB just filters out any lines not containing ttyUSB)

so that leaves us with the permissions, try chmod, if that works you probably aren’t running as the same user as you added to the dialout group after all; and also if it works you can move on to OTA flashing while you try to work out the permissions issue

I changed the permissions with chmod to 666 and I’m still getting the same error–I’m guessing it isn’t a permissions issue after all?

Presumably you also used sudo, and verified the permissions ls -l /dev/ttyUSB0?

Brings me back to, any chance you’re running with SELinux?

I had to look what SELinux was and I don’t think I am. Every command I tried in the CLI indicated it wasn’t installed so I’m thinking no.

then I’m all out of ideas, if everyone has read and write access to it, and its not in use then idk.

what happens if you try to open the (usb)serial port in a terminal like screen or minicom or whatever your favourite happens to be?

The only other thing I can suggest is try a different USB cable.