source: http://blog.sudonetworks.com/2010/03/configuring-wpawpa2-on-linux-clients.html
Configuring WPA/WPA2 for WiFi access on Linux Clients
Configuring a Linux WiFi client is not always as easy as with Windows or MAC OS X. In this first post I will show you how to configure your Linux client to associate with an access point. For this example, I use Ubuntu version 8.x. This procedure may vary from one Linux variant to another. The SSID I want to connect to is APN and my WiFi interface is wlan1. Here are the steps for WPA/WPA2 PSK (commands are in boldface):
1. Generate your WPA/WPA2 passphrase
~# wpa_passphrase [APN]
# reading passphrase from stdin
[enter yoursecretkey]
network={
ssid="APN"
#psk="yoursecretkey"
psk=9ae7a5f631ecc688db8dcc6bbf317b4a551b39e9ee9c20effb5393e342bd954b
}
2. Copy your wpa_passphrase
output to /etc/wpa_supplicant/wpa_supplicant.conf from the above step, it starts with “Network={” and ends with a closing curly brace “}”.
You may want delete the comment “#psk=yoursecretkey”
~# wpa_passphrase [APN] > /etc/wpa_supplicant/wpa_supplicant.conf
[enter yoursecretkey]
~# vi /etc/wpa_supplicant/wpa_supplicant.conf
3. Enable your wireless interface
~# ifconfig wlan1 up
4. Scan for existing WLANs or SSIDs
~# iwlist wlan1 scanning | grep -i essid
ESSID:”BELL078″
ESSID:”APN”
ESSID:”2mix”
You now have a confirmation your target SSID APN is detected.
5. Configure your wireless interface for your specific SSID
~# iwconfig wlan1 essid APN
6. Start WPA/WPA2 authentication
~# wpa_supplicant -i wlan1 -c /etc/wpa_supplicant/wpa_supplicant.conf
ioctl[SIOCGIWSCAN]: Resource temporarily unavailable
CTRL-EVENT-SCAN-RESULTS
Trying to associate with 00:25:4b:0a:a3:f5 (SSID='APNSmallBang' freq=2437 MHz)
CTRL-EVENT-SCAN-RESULTS
Associated with 00:25:4b:0a:a3:f5
WPA: Key negotiation completed with 00:25:4b:0a:a3:f5 [PTK=CCMP GTK=CCMP]
CTRL-EVENT-CONNECTED - Connection to 00:25:4b:0a:a3:f5 completed (auth) [id=0 id_str=]
7. Assign IP address via DHCP
Open a new shell to type the following command:
~# dhclient wlan1
Internet Systems Consortium DHCP Client V3.1.1
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/wlan1/00:c0:ca:2f:94:0d
Sending on LPF/wlan1/00:c0:ca:2f:94:0d
Sending on Socket/fallback
DHCPDISCOVER on wlan1 to 255.255.255.255 port 67 interval 3
DHCPOFFER of 172.16.22.5 from 172.16.22.1
DHCPREQUEST of 172.16.22.5 on wlan1 to 255.255.255.255 port 67
DHCPACK of 172.16.22.5 from 172.16.22.1
bound to 172.16.22.5 -- renewal in 33064 seconds.
8. Check if IP address assigned correctly
ifconfig wlan1
wlan1 Link encap:Ethernet HWaddr 00:c0:ca:2f:94:0d
inet addr:172.16.22.5 Bcast:172.16.22.255 Mask:255.255.255.0
inet6 addr: fe80::2c0:caff:fe2f:940d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1092 (1.0 KB) TX bytes:1580 (1.5 KB)
At this point, you should be connected to your AP