The ancient serial port which is no longer found on the latest motherboards and even the not so latest laptops is still used for connecting to the console of networking devices, headless computers and a lot other applications. On computers which do not have built-in serial ports USB-to-Serial adapters can be used. Linux identifies inbuilt serial ports as /dev/ttyS0, /dev/ttyS1,….. /dev/ttySn and USB-to-Serial adapters as /dev/ttyUSB0, …. /dev/ttyUSBn and they can be accessed using terminal emulator applications like PuTTY, minicom and screen.
Normally when the serial console is accessed using the terminal emulator of your choice as a non-root user you’ll get a “permission denied” error. Using PuTTY on Ubuntu I got the following error – “Unable to open connection to: Unable to open serial port“.
This is because the device file of the serial port does not have permissions to allow to currently logged in user to “read” or “write” to the serial device. The following command will confirm that.
jesin@localhost:~$ ls -l /dev/ttyUSB* crw-rw---- 1 root dialout 188, 0 Apr 8 21:54 /dev/ttyUSB0 crw-rw---- 1 root dialout 188, 1 Apr 8 21:54 /dev/ttyUSB1
So we can see that only the “root” user and the “dialout” group have proper permissions, while chmod can be used to grant access to the required user or everyone it is messy and not a secure way. The easier way is the add the user to the dialout group.
First verify if the user does belong to the dialout group using the “id” command.
jesin@localhost:~$ id -Gn jesin jesin adm cdrom sudo dip plugdev lpadmin sambashare kvm
Next add the user to the “dialout” supplementary group.
jesin@localhost:~$ sudo usermod -a -G dialout <username>
jesin@localhost:~$ sudo usermod -a -G dialout jesin
You have to logout and login before changes take effect. After logging back in try the “id” command again.
jesin@localhost:~$ id -Gn jesin jesin adm dialout cdrom sudo dip plugdev lpadmin sambashare kvm
Now all your terminal emulator applications will work with the serial port without any issues.