Skip to content

Instantly share code, notes, and snippets.

@goldfish07
Forked from buhman/00 wpa_cli passphrase network
Created July 5, 2019 13:47
Show Gist options
  • Save goldfish07/39b92787777a2581f0a7d08050d62e0b to your computer and use it in GitHub Desktop.
Save goldfish07/39b92787777a2581f0a7d08050d62e0b to your computer and use it in GitHub Desktop.
wpa_cli example; it might be worth mention that you can tab-complete all wpa_supplicant commands
[zack@leto ~]$ sudo tee << EOF /etc/wpa_supplicant.conf > /dev/null
ctrl_interface=/run/wpa_supplicant
EOF
[zack@leto ~]$ sudo wpa_supplicant -iwlp1s0 -Dnl80211 -c/etc/wpa_supplicant.conf -B
Successfully initialized wpa_supplicant
[zack@leto ~]$ sudo wpa_cli
wpa_cli v2.0
Copyright (c) 2004-2012, Jouni Malinen <[email protected]> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.
Selected interface 'wlp1s0'
Interactive mode
> status
wpa_state=DISCONNECTED
p2p_device_address=00:15:6d:85:5b:1f
address=00:15:6d:85:5b:1f
> scan
OK
<3>CTRL-EVENT-SCAN-RESULTS
> scan_results
bssid / frequency / signal level / flags / ssid
f8:1a:67:78:4b:af 2462 -34 [WPA2-PSK-CCMP][ESS] buhman
> add_network
0
> list_network
network id / ssid / bssid / flags
0 any [DISABLED]
> set_network 0 ssid "buhman"
OK
> set_network 0 psk "world domination"
OK
> list_network
network id / ssid / bssid / flags
0 buhman any [DISABLED]
> enable_network 0
OK
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>SME: Trying to authenticate with f8:1a:67:78:4b:af (SSID='buhman' freq=2462 MHz)
<3>Trying to associate with f8:1a:67:78:4b:af (SSID='buhman' freq=2462 MHz)
<3>Associated with f8:1a:67:78:4b:af
<3>WPA: Key negotiation completed with f8:1a:67:78:4b:af [PTK=CCMP GTK=CCMP]
<3>CTRL-EVENT-CONNECTED - Connection to f8:1a:67:78:4b:af completed [id=0 id_str=]
> status
bssid=f8:1a:67:78:4b:af
ssid=buhman
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
p2p_device_address=00:15:6d:85:5b:1f
address=00:15:6d:85:5b:1f
> list_networks
network id / ssid / bssid / flags
0 buhman any [CURRENT]
> set update_config 1
OK
> save_config
OK
> quit
[zack@leto ~]$ cat /etc/wpa_supplicant.conf
ctrl_interface=/run/wpa_supplicant
update_config=1
network={
ssid="buhman"
psk="world domination"
}
[zack@leto ~]$ dhcpcd wlp1s0
dhcpcd[20226]: version 6.1.0 starting
dhcpcd[20226]: wlp1s0: soliciting an IPv6 router
dhcpcd[20226]: wlp1s0: soliciting a DHCP lease
dhcpcd[20226]: wlp1s0: offered 192.168.1.100 from 192.168.1.1
dhcpcd[20226]: wlp1s0: leased 192.168.1.100 for 86400 seconds
dhcpcd[20226]: wlp1s0: adding host route to 192.168.1.100 via 127.0.0.1
dhcpcd[20226]: wlp1s0: adding route to 192.168.1.0/24
dhcpcd[20226]: wlp1s0: adding default route via 192.168.1.1
dhcpcd[20226]: forked to background, child pid 20319
[zack@leto ~]$ # now say we're going off to... starbucks or something and we want to connect to it; simple
[zack@leto ~]$ sudo wpa_cli
wpa_cli v2.0
Copyright (c) 2004-2012, Jouni Malinen <[email protected]> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.
Selected interface 'wlp1s0'
Interactive mode
> add_network
1
> set_network 1 ssid "starbucks"
OK
> set_network 1 key_mgmt NONE
OK
> list_networks
network id / ssid / bssid / flags
0 buhman any [CURRENT]
1 starbucks any [DISABLED]
> enable_network 1
OK
> select_network 1
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>SME: Trying to authenticate with 3e:20:1d:c6:0e:d2 (SSID='starbucks' freq=2412 MHz)
<3>Trying to associate with 3e:20:1d:c6:0e:d2 (SSID='starbucks' freq=2412 MHz)
<3>Associated with 3e:20:1d:c6:0e:d2
<3>CTRL-EVENT-CONNECTED - Connection to 3e:20:1d:c6:0e:d2 completed [id=0 id_str=]
> save_config
OK
> quit
[zack@leto ~]$ # all done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment