Wireless connection with Linux command line

Posted on

QUESTION :

I have a Java program to run on an Ubuntu box. This program should ask the user to enter the login and password of the wifi network with which it wants to connect and then the Java program must use the login and pass to connect automatically.

I found iwconfigm but it doesn’t work

I launched the command:

iwconfig wlan0 essid login key pass
Error for wireless request "Set Encode" (8B2A)
       invalide argument "pass"

So, how do I connect to the wireless network via the command line?

ANSWER :

The problem with giving this answer is that there is not a single answer, but very many, depending on the authorization scheme used.

Since most home networks use WPA/WPA2 with PSK, I will tell you how to do it in this case. A proper treatment of all possible subcases is too long for this forum.

   wpa_passphrase your_network_name your_password > wpa.conf
   ifconfig wlan0 down
   ifconfig wlan0 up
   iwconfig wlan0 essid your_network_name
   wpa_supplicant -B -Wnl80211 -i wlan0 -c wpa.conf
   dhclient wlan0

These commands have to be executed as root.

Leave a Reply

Your email address will not be published.