The serial port’s dark secret, and why you should always have a Plan B.

This post is certainly ham radio motivated, but it is 99% Linux.

This event happened during my “Intense Re-installation of Linux Period” (not to be confused with any other type of IRLP) described in the previous post.

I was working on the dual-boot T61 at the time, trying to get the JT65-HF program to run under Wine. For the most part it was okay, but one issue I was stumped by was getting the PTT line to key the radio, when it was my turn to transmit. The JT65-HF program, like many other ham digital applications, uses a COM port to toggle the PTT line of the radio, usually using the RTS or DTR line, connected through some kind of hardware interface, either commercial or homebrew. My interface happens to be a West Mountain Radio NoMic, which is about a simple as you can get. Of course, the T61 does not actually have any COM ports; it is common practice now to use USB to RS232 adapters, which present a “virtual” COM port to the digital apps.
All of this worked fine under WinXP, but I could see I was going to have to do a little figuring to get it going under Linux.

20131213_180923

USB to Serial Adapter, coiled and ready to strike.

After a little research on the Wine forums, I discovered that I had to softlink COM1 to my USB port, and all would be well. The USB serial port was showing up as /dev/ttyUSB0, so I knew at least that the drivers for the converter were working. Following the instructions I had found, I navigated to the appropriate wine directory, and created the soft link:

> cd ~/.wine/dosdevices
> ls -s /dev/ttyUSB0 COM1

The link appeared, and when I next ran JT65-HF, COM1 was offered as a choice for keying the radio. Home free! Except, it didn’t work. No reassuring relay click when I hit the TEST button. Nada.

Okay, back to the internet. I will omit some of the details of this search, and just tell you that the problem was so simple that I did not see it at first, looking right at it. Look at the directory listing for /dev/ttyUSB0, and you will see:

ttyUSB0_annotated

That’s right — the only users who have access are root, and members of the group dialout. My user, n2htt, was not by default in the dialout group.
I understand this is normal in Linux distributions; not granting rampant access to serial devices is a sort of security feature. Apparently this bit of intelligence is also widely known in the Linux community, but not by me at the time. Anyway, it now became clear that the solution to this problem was to add myself to the dialout group. [BTW HamOS takes care of this little detail for you, and automatically adds your new user to the dialout group, this avoiding this headache. Kudos to HamOS]

The command to add group membership in dialout to my user is the usermod command, issued like this:

>sudo usermod -a -Gdialout n2htt

the -G dialout specifies the group you want to join, and the -a indicates that this group membership should be added to the ones you already have.

Before we can get on with the story, you need to know what sudo is, and how it works. You Linux folk already know this and can skip down to the next paragraph. If you are a ham radio person, you may find this explaination interesting.

sudo is a neat command, it means “do the next thing as though I was the super-user”. The super-user (root) can do anything, so adding a group to your membership list is child’s play. You get to be a temporary super-user for a short period of time by entering your own password, but only if you have membership in the sudo group, a very exclusive club.

Access to the sudo command is controlled by file /etc/sudoers. In the following console you can see that accessing it requires root access, so when I tried first it failed, but when I added sudo and entered my password it listed the file. The area at the bottom of the file that is highlighted shows the all-important requirement that one belong to the sudo group in order to play.

explain_sudoers_anotated

Okay back to the story… The command I was supposed to issue was:

>sudo usermod -a -Gdialout n2htt

Unfortunately, the command I did issue was:

>sudo usermod -G dialout n2htt

Notice the fatal difference? Yes, I *replaced* all of my group memberships with just group membership in dialout.

my_groups_only_dialout_annotated

Okay no big problem, I’ll just put them all back:

>sudo usermod -a -Gn2htt,adm,sudo,cdrom,dip,plugdev,lpadmin,sambashare  n2htt

“You are not a member of sudoers! This incident will be reported!”

Uh-oh, that doesn’t look good. Can’t fix it, and I’ve been reported, too. So now I’m the only user of this machine, and I have no access to make administrative changes. I guess I’ll have to log in as root and fix this… Uh-oh, there is no root password set, I can’t log in as root, and no one can fix this…

I actually had to re-install Mint, which was annoying because I had been using this install for a while and it had already begun to acquire “character”. There was no other way to fix it.

This is where Plan B comes in: from that point on, I created a login password for root everytime time I installed a distro. I understand that this is frowned on as a general practice, but in the context of a single-owner machine used for hobby purposes, it can really save your bacon. It is easy to do, too. All you need to do (before you remove yourself from the sudo group) is issue this command:

>sudo passwd

You will be prompted for your password (for sudo), then for the new root password twice. That’s it, you’re done, and you have insurance against any potentially devastating newbie mistakes. I do have to point out though that:

  • With great power comes great responsibility
  • Absolute power corrupts absolutely

You’re on your own there.

73,
de N2HTT

This entry was posted in Linux and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.