Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The wireless networks are detected, but I am unable to connect to them.

Here is the code I've tried:

sudo iwlist wlan0 scan (Working)
iwconfig wlan0 essid "Network name" key s:"key" (Error for wireless request "Set Encode" (8B2A)) SET failed on device wlan0 ; Invalid argument

wpa_passphrase essid password > /etc/wpa_supplicant.conf
wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument

Then i tried by adding ctrl_interface=/var/run/wpa_supplicant at the beginning of file wpa_supplicant.conf and running the same wpa_supplicant command but result is

ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ctrl_iface exists and seems to be in use - cannot override it
Delete '/var/run/wpa_supplicant/wlan0' manually if it is not used anymore
Failed to initialize control interface '/var/run/wpa_supplicant'.
You may have another wpa_supplicant process already running or the file was
left by an unclean termination of wpa_supplicant in which case you will need
to manually remove this file before starting wpa_supplicant again.

How do I connect to a specified wireless network through command line in Ubuntu 12.04?

share|improve this question
key s:"key" implies that your key is WEP and ASCII. Your wpa_supplicant.conf implies it is WPA. Which is it? Are you able to use vim to amend /etc/network/interfaces? – chili555 Aug 8 '13 at 19:30
It is WPA2. 'vi amend /etc/network/interfaces' contains 'auto lo iface lo inet loopback'. Manually its connecting but i want to connect through command line.(DHCP Client) – Arjun Kanti Aug 9 '13 at 6:32
Please explain 'manually it's connecting.' Is Network Manager running or is this a server without a desktop? – chili555 Aug 9 '13 at 12:23

This short article helped me connect my 12.04 LTS server to my WPA2 PSK network: prupert @ WordPress . I run the server without desktop, so it demanded all cmd line.

I am paraphrasing a quick breakdown of the steps, but please click on the link for the full article:

(You Need to be connected to the network at this point)

Install The Software:

(You only need WPASupplicant if it is not an open network) sudo apt-get install wireless-tools wpasupplicant

Activate your wireless network:

sudo ifconfig wlan0 up

To Check The Wireless Run:



sudo iwlist scan

(The sacn command should return visible wireless networks, but if it does not it is a sign that there are none visible or something is wrong with your HW/SW outside the scope of the linked article)

Run: (To recieve you WiFi Key)


A Sample of The Resulting Text: (As Provided by the Linked Article)

psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a

Copy the "psk" somewhere accessible, this is going to allow you to connect to your network.

Edit your interfaces file:

sudo nano /etc/network/interfaces

Append your WiFi network to the end of this file using the folling options and syntax:

auto wlan0     #change this to the name of your WiFi interface
iface wlan0 inet dhcp     #this is normally fine, if you want a static IP address replace “dhcp” with “static”
netmask     #change this as appropriate for your network, this value is usually right
gateway     #change this as appropriate for your network
address     #only needed for a static IP address
dns-nameservers     #only needed for a static IP address
wpa-driver wext     #you shouldn’t need to change this
wpa-ssid YOURSSID     #just type the name of your SSID here
wpa-ap-scan 1     #if the name of your SSID is hidden usually, type 2 instead of 1
wpa-proto WPA    #if you use WPA1 type WPA, if you use WPA2 type RSN
wpa-pairwise CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-group CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-key-mgmt WPA-PSK     #usually WPA-PSK (if you share a key) but sometimes WPA-EAP (for enterprises)
wpa-psk YOURHEXKEYFROMABOVE     #the hex key that you generated earlier

Example from Author of the linked article:

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid MYPLACE
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk 71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc

You may now comment out the top of the Interfaces file, which will disable the ethernet. The author of the article reccommends this to prevent conflicts, but I decided not to as the only way that I can access my server interface is via PuTTY SSH, so I want to have a method of connection if the wireless is down, where I don't need to break out a mouse and monitor: (Remove the "#" later if you need the ethernet connections to work again)

#auto eth0
#iface eth0 inet dhcp

Write Out the file and Save your Changes Reboot your Machine

If this doesn't work, you may need to edit the Config file for the WPASupplicant program:

sudo nano /etc/wpa_supplicant.conf

You edit this file with much of the same information, except the wpa- piece: (A sample below from the author of the linked document)


"As far as I am aware, the options are the same. So, edit this file as necessary, make sure you add the ctrl_interface and network={ at the beginning and the } part at the end. Save it and try restarting again. If it still doesn’t work, then kick your PC, wish you had installed Windows 7 instead and go off and do some Googling. You’ll find the answer on the Ubuntu forums and you’ll be happy again.

Best of luck!" - prupert

share|improve this answer
Arjun. If you are to attempt to use this answer for your case, then make sure you take into account any changes that you have already made to various conf files as stated in your original question – Burly Ares Feb 26 '14 at 23:46
thanks for this answer , but how can I set the operation mode to ad-hoc in this configuration ? – Suda.nese Sep 12 '14 at 14:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.