The Field notes of an Audacious Amateur series is offered in the spirit of the open source movement. While the concept of open source is typically associated with computer programmers, there is a growing body of those who don't know jack about programming, but who nevertheless use the creations of open source programmers. . . .

This series is written by a representative of the latter group, which is comprised mostly of what might be called "productivity users" (perhaps "tinkerly productivity users?"). Though my lack of training precludes me from writing code or improving anyone else's, I can, nonetheless, try and figure out creative ways of utilizing open source programs. And again, because of my lack of expertise, though I may be capable of deploying open source programs in creative ways, my modest technical acumen hinders me from utilizing those programs in what may be the most optimal ways. The open-source character, then, of this series, consists in my presentation to the community of open source users and programmers of my own crude and halting attempts at accomplishing computing tasks, in the hope that those who are more knowledgeable than me can offer advice, alternatives, and corrections. The desired end result is the discovery, through a communal process, of optimal and/or alternate ways of accomplishing the sorts of tasks that I and other open source productivity users need to perform.

Saturday, April 28, 2012

Sixth installment: establishing wifi connections from the command line

Reader's Digest condensed version

Want to get on a wifi network fairly quickly and painlessly from the command line? Try network-manager's command-line cousin, cnetworkmanager. A command like sudo cnetworkmanager -C essid-of-network --unprotected (for unprotected networks) will do it. For further details on how I discovered this and for further remarks on cnetworkmanager's capabilities, read below.

Unabridged version

Trailing edge technologist that I am, I'm also a fan of minimalist desktops. I've used mainly ion2/3, dwm, and evilwm for day-to-day computing--though I've tried out many others like JWM, icewm, fluxbox, blackbox, twm, openbox, etc.

After my netbook's keyboard went on the fritz subsequent to having water squirted on it by a loved one (I can say she's a loved one in hindsight), I decided to dig out an old laptop and press it back into service. It is, of course, a single-core machine with a Celeron 2.4 Ghz CPU and only 512 MB RAM. So, another ideal candidate for a minimalist desktop.

I wanted to get the machine up in a hurry so I chose to install a lighter-weight *buntu on it--namely, Lubuntu. That variant uses the lightweight LXDE desktop.

After I'd gotten it set up and used it for awhile, I decided to try paring back the system resource usage yet further. The main means toward that end was to install the evilwm window manager which, though I understand it is not quite as lightweight as dwm, nevertheless looked like a good choice for this machine.

It took some trickery to be able to load into the evilwm desktop once the machine was booted. Lubuntu, you see, uses the LXDM login manager, and I was unable to create a valid menu entry for an evilwm session. So I used the quick and dirty method: cobble together an .xinitrc for evilwm, kill LXDM, then issue startx from the command line.

I'm in the initial stages of possibly replacing LXDE with evilwm on this laptop, but I've gotten at least partway there. I want to recount in this entry how I managed to get wifi connections working under evilwm. But first, a relevant digression.

I used to use command-line routines on another old laptop some years ago when connecting to wifi networks. That involved using commands such as iwlist and iwconfig, then issuing a dhcp request on the wifi NIC. At a certain point, however, my trusted command line routines stopped working for reasons I could not understand.

Searching for alternatives, I discovered wicd. I actually doubted it would work since, as I understood it, wicd was simply a series of python scripts that invoked the same command-line binaries I'd been unsuccessfully attempting to use.

But wicddid work, and to my delight, I even discovered that it had a curses, terminal interface: I thus needed not be bothered with using a pesky gui utility to employ wicd. I subsequently came to rely on wicd for establishing and managing wifi connections.

Getting back to evilwm; those who are familiar with that window manager will be aware how minimalistic it is: there are no taskbars, no system trays, no pop-up menus. No, all evilwm does is display the desktop background you specify and allow you to open graphical applications (invoked from a terminal or by using something like xbindkeys and gmrun).

That sparseness presented an issue with wifi connections once I started switching from LXDE to evilwm: you see, Lubuntu has set up this system such that it uses network-manager for managing wifi connections, and network-manager, in turn, expects there to be a system tray in which it can reside. Given that architecture, I could see no way in which I could use network-manager for my wifi connections while running evilwm.

My first assumption was that my old standby, wicd, would allow me to manage wifi connections under evilwm. So I installed it. But it would not, no way, no how, allow me reliably to connect to wifi networks.

I am uncertain why this problem exists. I read that it was related to some conflict with network-manager, and that the solution was to uninstall network-manager. But doing that did not resolve my problems: wicd would, for the most part, give me a "bad password" error and would not connect to the network: perhaps once in every thirty tries I could get on-line, but the other twenty-nine times, I would get the bad password error.

Short story long, I had to abandon wicd and look into other ways of connecting my laptop to wifi networks using command line utilities. My attempts at finding an alternative to wicd finally resulted in the discovery that there is actually a command line version of network-manager called cnetworkmanager.

The happy ending to this story is that cnetworkmanager's man page is fairly simple and easy to comprehend for the non-specialist. I was, in very short order, able to bring up my wifi network connection using cnetworkmanager. Below are salient details.

In order to find the name of your wifi network interface and, at the same time, scan for essid's of detected networks, the command cnetworkmanager -a -d run in a terminal does the trick (-a is the option that lists available networks, -d is the switch that tells you the names of wifi interfaces on the machine being used). With that information it is fairly simple--though super-user privileges are required for this--to a network as follows.

For WPA-encrypted networks, the command sudo cnetworkmanager -C essid-name --wpa-pass=password will do the trick. For unencrypted networks, sudo cnetworkmanager -C essid --unprotected does the job.

It's a bit clunky, but provides a workable solution that gets me by for now.

4 comments:

I just tried your suggestion for cnetworkmanager, and it works great. I also use wicd, although I have found you can run it without having to use the system tray. You just enter the command wicd-client -n.

I have also used the tools ifconfig, iwconfig, and dhclient to bring up a wireless interface from the command line. I have not been able to figure out how to use WPA encryption using those tools. It looks like that will be solved with cnetworkmanager.

One tried running cnetworkmanager from the terminal interface before logging into the GUI. (I use icewm.) Unlike the tools ifconfig, etc, I cannot then issue the startx command. The only option for a command-line only system is to use the screen command to open multiple windows.

I enjoyed reading your blog post. I would also describe myself as a minimalist. I like to get older computers running with linux. Several of mine have 128mb of RAM or less.

What you need to do with a WPA encrypted network is to use wpa_supplicant.You can generate the config file with wpa_passphrase like this:# wpa_passphrase mywireless_ssid "secretpassphrase" >> /etc/wpa_supplicant.conf

After this is done, you will need to run wpa_supplicant with the relevant parameters:

# wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

Once this is done, wpa_supplicant will be connect and create the encrypted connection. After that you can run dhclient/dhcpcd depending on your system, and the DHCP server will give you the address - so you are connected.

There is a good discussion of the details on the Arch wiki:https://wiki.archlinux.org/index.php/WPA_supplicant

- but it is really easy to make all this look more difficult than it really is! Because it is just a case of making wpa_passphrase create a config file based on your network settings, have wpa_supplicant open the connection, and then you just use the regular tools to get the IP address.

Yes, I discovered the -n option for wicd fairly early on. But I came to prefer the terminal, curses version (wicd-curses). Did you try appending & after your cnetworkmanager command? That would cause the process to run in the background, then other commands could be run in that same terminal, such as startx. But then you'd lose the ability to easily stop cnetworkmanager. I guess in that latter case you'd have to find the process ID and issue the kill command to stop cnetworkmanager and bring down the connection. This cnetworkmanager approach has its drawbacks, but much to commend it as well. Glad you found this entry helpful.

This idea of opening up a wifi connection via a specified BSSID interests me; I've been (too briefly) looking for ways to sidetrack the problem of network-manager's (and wicd's, for that matter) inherent desire to just latch onto the strongest signal, and in an open public WiFi environment where there are multiple channels with the same SSID, you get used to knowing which channels and/or MAC addresses are legit, so it's a good way of bypassing any attempts at MITM attacks. I hadn't got as far as finding out that cnetwork-manager existed or whether it was installed on a fedora distro by default (I don't remember seeing it in the /bin list). Presumably this command may do what I need!

Disclaimer: the techniques described above have been developed and deployed by a rank amateur who knows next to nothing about proper protocol for operating computers, much less about how to use them optimally or safely. Following the procedures described may result in the malfunction or self-destruction of computer equipment, the death of your dog, premature hair loss, disruption of the cosmic balance of the entire universe, or some sinister conjunction of all the above. Follow these directives at your own risk!