Connecting to wpa/wpa2 protected Wi-Fi network without GUI frontends

When I started using Arch I found myself having problems with connecting to my Wi-Fi network with the usual GUI frontends (network-manager and Wicd). Luckily there is another method to do these things if the GUI way falls short. In order to connect to wpa or wpa2 network you will need the following packages:

wpa_supplicant and wireless-tools. Wireless-tools might not be strictly necessary but having it does no harm. You may also need to install dhclient, in some cases.

In Ubuntu/Linux Mint: sudo apt-get install wireless-tools  wpa_supplicant

In Debian: su root

apt-get install wireless-tools  wpa_supplicant

In Fedora: su root

yum install wireless-tools  wpa_supplicant

In Arch Linux: su root

pacman -S  wireless_tools wpa_supplicant

The previous entries are provided as an examples in case you are still learning Linux. After you have installed these packages become a root user by typing su root in terminal. You can of course use sudo as well if you are running a system which has that as a default choice (Ubuntu,Linux Mint…). Next you need to edit or create a file called /etc/wpa_supplicant.conf . So once you are in a terminal as a root user type: nano /etc/wpa_supplicant.conf

In the example nano is a text editor which you can replace with your own prefered choice. If you are using sudo you can execute the whole command like this while you are in a terminal: sudo nano /etc/wpa_supplicant.conf

Once you are inside the file /etc/wpa_supplicant.conf  add following entries to it

network={
ssid=”Network_name”
psk=”your_password”
}

In the field “Network name” you should type your network name like this: “Myonline” and in the field psk the password like this: “1234567” . So whatever you type inside ssid and psk you do not remove the quotation marks around the written texts because otherwise you will get an error. Once you are done setuping the file safe it and exit it.

When you want to connect to your wpa/wpa2  protected Wi-Fi execute the following command as a root user or by the means of using sudo in front of the command: wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext && dhclient wlan0

What this command basically does is telling wpa_supplicant daemon to run in the background and look at the configuration entries located inside the file /etc/wpa_supplicant.conf
and after that startup wpa/wpa2 encrypted Wi-Fi network using wext driver and finally it is instructed that wireless  network card/adapter is being found from interface address wlan0 and it uses dhcp to connect to the Internet.

For more information about the various ways and possibilities of using dhclient and wpa_supplicant commands you can  check out their manual pages by typing the following commands inside the terminal as a normal user: man dhclient

man wpa_supplicant

Note: your Wi-Fi adapter or card might be in a different location so if you get an error saying that no wlan is found from the location wlan0 you might try out for example wlan1. Wlan0 is the usual suspect when finding the location but things might still be different in your configuration.

Downsides of  connecting to wpa/wpa2 without the Gui frontends:

First downside is that you will need to execute the connection command ( wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant.conf -Dwext && dhclient wlan0 )  as a root or sudo every time you restart your computer. This can however be seen also as a security feature since you will certainly have a greater control when it comes to using and activating your Internet connection. Also worth mentioning is that I needed to unplug and replug my Wlan adapter if I did a system reboot. This might be a problem specific to my system configuration but just in case someone else experiences a similar problem with a usb Wlan adapter be noted that you are not alone.