Connect to Wireless Network (WPA) in Ubuntu 11.04 using Command Line

Install wpa supplicant package:

$ sudo apt-get install wpasupplicant

Configure network ESSID and passphrase.
In this example I use ESSID ‘yantoknuk-singtel’ and passphrase ‘ngumbahkucing’.

$ wpa_passphrase yantoknuk-singtel
# reading passphrase from stdin

After that, type in your passphrase right below the text ‘# reading passphrase from stdin’.

# reading passphrase from stdin
ngumbahkucing
network={
ssid="yantoknuk-singtel"
#psk="ngumbahkucing"
psk=1e6eb493adf24740e2d3e98759b8b985e69f0bb939931c19400ceeecb61788e1
}

Edit or create /etc/wpa_supplicant.conf:

$ sudo nano /etc/wpa_supplicant

And then type in the following lines which is produced by wpa_passphrase before:

network={
ssid="yantoknuk-singtel"
#psk="ngumbahkucing"
psk=1e6eb493adf24740e2d3e98759b8b985e69f0bb939931c19400ceeecb61788e1
}

Save and exit nano.
To test the configuration, execute this:

$ sudo wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -Dwext

If it’s successful you should see something like the following:

Trying to associate with 00:ff:00:1e:a7:7d (SSID='yantoknuk-singtel' freq=0 MHz)
Associated with 00:ff:00:1e:a7:7d
WPA: Key negotiation completed with 00:ff:00:1e:a7:7d [PTK=TKIP GTK=TKIP]

It’s finish. Your computer is now associated / connected to the access point.
To make it autorun on boot, add in these lines to /etc/network/interfaces:

$ sudo nano /etc/network/interfaces

And add the following lines:

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf

That’s all. The complete information can be read here