Configure WPA wireless from command line

In the old days, when WEP was still considered secure, configuring your wireless connection from a Linux command line was trivial:

$ sudo iwconfig eth1 essid awesomenet mode Managed enc on key AABBCC1122
$ sudo dhclient eth1

But in the here and the now, we use WPA for better security. One fine day, I was stuck without a GUI wireless configurator (or NetworkManager threw a fit again - I don’t remember now) and was completely clueless as to how to use the CLI tools to get WPA going. Forget how, I didn’t even know which tools! And needless to say, I couldn’t just Google for it! The man pages were too detailed to make any sense. In the end, I did figure it out and here’s what I had to do:

1) Generate a passphrase file

$ wpa_passphrase awesomenet awesomephrase > ~/awesomenet.wpa

2) Then, associate it.

$ sudo wpa_supplicant -i eth1 -c ~/awesomenet.wpa -D wext -B

3) Finally, get IP!

$ sudo dhclient eth1

There. Now the next time I am stuck configuring WPA from the command line, I’ll just look up this post. Oh wait…