Ubuntu – How to connect to a WPA wifi network using the command line

command linewirelesswpa

So basically, I'd like to use iwconfig to connect to my wifi network when I'm not inside X. But I just don't see a way to do it in the man page. Any idea?

Best Answer

iw (list/config) can only handle WEP.

You need the wpasupplicant package which provides the wpa_supplicant command, install if necessary through sudo apt-get install wpasupplicant.

You put your SSID and password into /etc/wpa_supplicant.conf (requires sudo).

Example:

network={
    ssid="ssid_name"
    psk="password"
}

Assuming your interface is wlan0 you can connect with:

sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
sudo dhclient wlan0

"wext" is a driver and that will be specific for each card; refer to wpa_supplicant -h. Examples:

hostap (default) Host AP driver (Intersil Prism2/2.5/3). (this can also be used with Linuxant DriverLoader).
hermes Agere Systems Inc. driver (Hermes-I/Hermes-II).
madwifi MADWIFI 802.11 support (Atheros, etc.).
atmel ATMEL AT76C5XXx (USB, PCMCIA).
wext Linux wireless extensions (generic).
ndiswrapper Linux ndiswrapper.
broadcom Broadcom wl.o driver.
ipw Intel ipw2100/2200 driver.
wired wpa_supplicant wired Ethernet driver
roboswitch wpa_supplicant Broadcom switch driver
bsd BSD 802.11 support (Atheros, etc.).
ndis Windows NDIS driver.