USB device in LXC, need to set permissions everytime it boots


I have an USB device for my home automation.
Every time my container boots I need to do chmod 666 /dev/ttyUSB0 before my systemd daemon starts, otherwise I get a permission denied:
mqttbroker npm[1189]: #033[31mZigbee2MQTT:error#033[39m 2020-10-31 15:30:43: Error: Error while opening serialport 'Error: Error: Permission denied, cannot open /dev/ttyUSB0'

Is there a permanent way to fix this?
I added the USB with:
lxc config device add mqttbroker ttyusb unix-char path=/dev/ttyUSB0

EDIT: Some version info:

# lxd --version
# uname -a
Linux server-01 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Have a look at the full documentation for unix-char,

There should be no issue with access of the device from the host. You should set the uid, gid, mode so that in the instance (the container) mqttbroker is happy.

Thanks simos! I am unable to find how to exactly set the unix-char.
Do I do this via lxc config device command?

Thank you.

Yeah, you can pass uid= gid= mode= to the add command or you can run lxc config edit to change things through a text editor.

Thank you, didn’t get that from the man page or anywhere else on the internet.
Adding mode= did the job for me.

Those properties are documented at the link that @simos gave you.

That is correct, though it was not clear to me that you can pass these options via the lxc config device add. :slight_smile: