Search This Blog

Monday, 17 October 2016

Using a USB Serial cable on Ubuntu (without needing to sudo)

For those who know me, my views on using Windows as a desktop environment are well known. I wouldn't say it was necessarily a bad thing, it works for a great number of people, but for those of us in the world who care about freedom, choice and the greater good, then there are numerous alternatives.

My house is filled with precisely one laptop, and that's a Chromebook. I'm fairly well invested in the Google ecosystem, and it works well for me.  My company however have provided me with two laptops, one for doing my company business (e-mails, documentation, and the like), and one for conducting business on customer sites (networking tasks mainly).

My networking laptop was handed to me with Windows 8.1, as was the company standard at the time, and I subsequently (read very quickly) removed Windows and installed Ubuntu Gnome. I love Ubuntu Gnome, I find it to be a very clean, efficient and fast operating system, and works perfectly for my needs. When there is a need to do anything "Windows-ish", I have a VirtualBox VM running Windows 10.

Now, I'm a networking man, and my terminal emulator of choice has always been PuTTY. One of the annoyances I find with PuTTY is that as a user or administrator on an Ubuntu system, you need to run PuTTY using a sudo command to avoid the application showing the error message "Putty Fatal Error: Unable to open connection to: Unable to open serial port" when PuTTY tries to interact with the USB Serial Port. This can be worked around by launching a terminal window within Ubuntu, and running the following command:

sudo putty

This is all well and good, and will get you round the issue without any problems.  However, for me, this always seemed like an unnecessary obstacle to me getting my work done.

After a little investigation, I found that when I connect my USB Serial port to my laptop, it gets installed on Ubuntu as a device called /dev/ttyUSB0, and this device is a member of a group called "dialout", as shown in the screenshot below:



This theoretically meant that if my user account were a member of the "dialout" group, it would have the relevant permissions to access the port.  I checked my group membership be running the command "groups"



As I suspected, there is no reference to the group "dialout" in my list of groups.  By running the following command, I was able to add the "dialout" group to my list of groups.

sudo usermod -a -G dialout david

You need to log out and then back in to apply the changes.  When you the run the command "groups", you will see that "dialout" in the list of groups.




This too should work for you, if you substitute my username above "david" for your own username on the system.

Just for your information, the above command is broken down to illustrate what is happening:

sudo: run the following with highest privileges
usermod: invoke the user modification program
-a: specifies that usermod should be adding an entry
-G (note the capital G): specifies that what follows is an addition to an existing group
dialout: this is the group to which a user should be added
david: is the user who should be added to the above group

I hope this helps someone
Have a nice day
Dave