Configure WiFi on Raspberry Pi Raspbian / Debian Linux via Command Line

29 Apr

Configure WiFi on Raspberry Pi Raspbian / Debian Linux via Command Line

By | 2016/01/17

To easily scan for wireless networks and connect on a Raspberry Pi, use the command line app wpa_cli. Check it out!


Here is how to scan for and connect to wireless networks from the command line on a Raspberry Pi!

1. Run:

sudo wpa_cli

This will open up an interactive mode.

wpa_cli v2.3
Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode

>

Next, type the following commands at the > prompt to scan for available networks:


scan
scan_results

Ex. output:

> scan_results
bssid / frequency / signal level / flags / ssid
30:e2:c2:0b:73:23       2412    100     [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]    scottlinux

2. Add a network:

add_network 0

3. Set this network to the desired SSID you wish to connect to.

set_network 0 ssid "scottlinux"

4. Set the passphrase for that SSID.

set_network 0 psk "averycoolpassphrase"

5. Enable then save the network and settings.

enable network 0
save_config

Done.


Below is an example full output:

pi@raspberrypi ~ $ sudo wpa_cli
wpa_cli v2.3
Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode

> scan
OK
<3>CTRL-EVENT-SCAN-RESULTS 
<3>WPS-AP-AVAILABLE 
> scan_results
bssid / frequency / signal level / flags / ssid
30:e2:c2:0b:73:23       2412    100     [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]    scottlinux
46:52:3a:b2:3b:51       2457    7       [WPA2-EAP-CCMP][ESS]    TWCWiFi-Passpoint
a8:3c:59:7b:15:f7       2412    68      [WPA2-PSK-CCMP][WPS][ESS]
> add_network
0
> set_network 0 ssid "scottlinux"
OK
> set_network 0 psk "averycoolpassphrase"
OK
> enable network 0
OK
<3>CTRL-EVENT-SCAN-RESULTS 
<3>WPS-AP-AVAILABLE 
<3>Trying to associate with 30:e2:c2:0b:73:23 (SSID='scottlinux' freq=2412 MHz)
<3>Association request to the driver failed
<3>Associated with 30:e2:c2:0b:73:23
<3>WPA: Key negotiation completed with 30:e2:c2:0b:73:23 [PTK=CCMP GTK=TKIP]
<3>CTRL-EVENT-CONNECTED - Connection to 30:e2:c2:0b:73:23 completed [id=0 id_str=]
> save_config
OK
> quit
pi@raspberrypi ~ $