[SOLVED] How to read from a serial device without sudo-rights? lazarus / 32-Linux ---------------------------------------------------------------------- Hartmut · 2023-02-24 16:18 My program uses unit SynaSer from Synapse to read data from a serial device. Everything is fine, but my program needs sudo rights. I want to avoid this. In https://wiki.freepascal.org/Hardware_Access#Device_Setup is written: QuoteBefore starting, make sure to authorize your device on Linux. An option is to create a persistent UDEV rule for each device. For example, the following approach apply mode "0064" for the device specified by 'serial', 'idVendor' and 'idProduct' attributes: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # create a new dev rule based on some constantsecho 'SUBSYSTEM=="tty", ATTRS{serial}=="A1004chl", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0664"' | sudo tee /etc/udev/rules.d/50-usb-serial.rules > /dev/null # reload rulessudo udevadm control --reload-rules # re-add all devicessudo udevadm trigger # testls -al /dev/ttyUSB0 # you may want to reboot your systemsudo reboot I don't understand this, but it sounds to me like this could be a way to avoid sudo-rights. Is this correct? If yes, please help me to find the correct commands for my case. My program uses '/dev/ttyS0'. I don't know Vendor-ID or Product-ID etc. I'm a bloody beginner to this kind of Linux stuff, so some explainations what your command does would be very welcome. I'm on Linux Ubuntu 18.04. Thanks in advance. ---------------------------------------------------------------------- TRon · 2023-02-24 16:23 The first hit I got when searching for the topic was this You would have to figure out how things are setup on your linux distro but it should be similar. For vendor/product id see this ---------------------------------------------------------------------- Bogen85 · 2023-02-24 16:27 The udev rules are needed. They set up the device with the correct ownership. You can't rely on simply changing the owner/group/permissions as the device nodes are created in a temporary directory and the names are not always the same. In the udev rules can also make provide a consistent device name that you can use. ---------------------------------------------------------------------- Bogen85 · 2023-02-24 16:30 The udev rule setup is the same for most mainstream Linux distros (Debian/Ubuntu and based on them, arch and based on it, Fedora and based on it, and many others, and has not changed in over 10 years). ---------------------------------------------------------------------- Bogen85 · 2023-02-24 16:31 https://dev.to/enbis/how-udev-rules-can-help-us-to-recognize-a-usb-to- serial-device-over-dev-tty-interface-pbk https://www.thegeekdiary.com/how-to-configure-device-file-owner-group- with-udev-rules/ ---------------------------------------------------------------------- MarkMLl · 2023-02-24 17:09 Most distreaux have a dialout group for the serial ports, and users authorised to use them should be a member. MarkMLl ---------------------------------------------------------------------- Bogen85 · 2023-02-24 17:25 Quote from: MarkMLl on February 24, 2023, 06:09:23 pmMost distreaux have a dialout group for the serial ports, and users authorised to use them should be a member. Ah, of course. As long as the device name is not changing, just being in the correct group should be sufficient. ---------------------------------------------------------------------- Hartmut · 2023-02-24 17:30 The solution was:    sudo usermod -a -G dialout $USER and to log off and log in again. I did not know how to find out, if device '/dev/ttyS0' is owned by user group 'dialout', so I just tried it and it worked :-) Thanks to all who helped me. ---------------------------------------------------------------------- MarkMLl · 2023-02-24 17:36 ls -lt /dev/tty* | head     and so on, where that will list the most- recently-hotplugged devices first. You /might/ find that you need to mess around with udev rules if a particular family of serial devices isn't correctly being moved into the dialout group when hotplugged, but I don't recall having to do that for a significant number of years. MarkMLl ---------------------------------------------------------------------- Bogen85 · 2023-02-24 17:37 Quote from: Hartmut on February 24, 2023, 06:30:00 pmThe solution was:    sudo usermod -a -G dialout $USER and to log off and log in again. Good to hear! Quote from: Hartmut on February 24, 2023, 06:30:00 pmI did not know how to find out, if device '/dev/ttyS0' is owned by user group 'dialout', so I just tried it and it worked :-) Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ls -l /dev/ttyS0 Quote from: Hartmut on February 24, 2023, 06:30:00 pmThanks to all who helped me. MarkMLI's answer was the best one.