December 18th, 2009

Connecting to a WPA WiFi network on Linux (CLI)

Most articles make this out to be much more complicated than it needs to be. First, make sure you have wpa_supplicant. On Archlinux:

$ sudo pacman -S wpa_supplicant

You will need to add your network definition to wpa_supplicant.conf:

# wpa_passphrase YOUR_SSID YOUR_PASSPHRASE >> /etc/wpa_supplicant.conf

Finally, create a script to bring the interface up. I put mine in ~/scripts/

sudo pkill wpa_supplicant
sudo pkill dhcpcd
sudo ifconfig wlan0 up
sudo iwconfig wlan0 essid YOUR_SSID
sudo wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
sudo dhcpcd wlan0

Change your ssid and interface accordingly. Run that script to connect!