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

How do I setup Wifi using the command line?

I need to setup as following, but its failed:


Security: WEP
Network name: wifi59/7
Key/password: xyz

Tried and failed:

sudo iwconfig wlan0 mode managed
sudo iwconfig wlan0 channel 11
sudo iwconfig wlan0 essid wifi59/7
sudo iwconfig wlan0 key xyz
Error for wireless request "Set Encode" (8B2A) :
    SET failed on device wlan0 ; Invalid argument.
share|improve this question
up vote 7 down vote accepted

The WEP key should be in hex, and either 10 or 26 characters long (5 or 13 ASCII bytes).

If you want to specify it in ASCII, you have to prefix it with s: - I'm not sure if iwconfig will pad out an ASCII password, but try lengths of 5 or 13.

See man iwconfig and scroll down to key/enc[ryption] for some examples.

share|improve this answer

I think it is easier and more reliable to use networkmanager's default command line utiliy called nm-cli. Please have a look at nm-cli to familiarize yourself with nm-cli syntax.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

This is my solution:

$sudo vi /etc/network/interfaces

#The primary network interface
auto wlan0
iface wlan0 inet static
# wireless-* options are implemented by the wireless-tools package
wireless-mode managed
wireless-essid YOUR_SSID
wireless-key1 s:YOUR_PASS
share|improve this answer

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.