Connecting to WPA/WPA2 PSK network using command line

November 13th, 2011  Posted at   Linux

When we want to connect to a wireless network protected using WPA/WPA2 schema using command line we cannot use iwconfig to achieve it. We need to use a “supplicant” program. The most common is wpa_supplicant. To use this program we need to provide it a config file, so let’s do it.

Create a new file with the following content:

# WPA/WPA2 PSK Config file






Where “MyNetwork” is the name (ESSID) of the network you want to connect to and “MyKey” is the Pre-Shared Key for the network.

Save this file wherever you want. I’ll use /root/wpa.conf (I’m using BT5 right now :)).

** If the example file configuration does not meet your requirements you can find other configurations in the following file:;a=blob_plain;f=wpa_supplicant/wpa_supplicant.conf

The interface I’ll be using for this connection is eth1.

The command we need to launch to finally connect to this network is the following:

wpa_supplicant -Dwext -c/root/wpa.conf -ieth1

Parameters meaning:

-D driver to use. (wext -> Linux wireless extensions (generic))

-c config file to use. (/root/wpa.conf -> our new config file)

-i interface to use. (eth1 -> my wireless interface)

As the wpa_supplicant command that we use needs to be active permanently while we are connected to the network it’s better to launch it in the background so we’ll use the following command:

wpa_supplicant -Dwext -c/root/wpa.conf -ieth1 &

If you’re using a graphical interface like Gnome or KDE you can also press ALT+F2 to run the program in background mode:

And that’s it, you’re connected.

Remember that once you’ve done this you need to configure the IP parameters for the network. If there is a DHCP server running you can use:

dhclient eth1


One Response to “Connecting to WPA/WPA2 PSK network using command line”

  1. says:

    If youu want reading news, have you thought to use an online mell b breaking
    news –, aggregate to aid increase
    your comprehension skills inside the new vernacular. Then write
    the way it seems like to you and pay attention because you lay
    them out to find out more on yourself and view the
    way you will find the hidde lesson. The person who I quoted at the outset of this article
    has actually done an awesome job during the last year and a half, using solcial media marketing to create
    a large and responsive list for himself.

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.