Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a network profile from etc/wpa_supplicant/wpa_supplicant.conf through command line / shell script

I have multiple wifi network ssid's saved in my etc/wpa_supplicant/wpa_supplicant.conf like shown below, can we delete a specific network from this wpa_supplicant.conf

Ex: in the below networks can a delete the network myssid1 through a shell script which i can then execute through node.js server

 network={
            ssid="myssid1"
            scan_ssid=0
            proto=WPA
            key_mgmt=WPA-PSK
            psk=5f55a9b869e9ab6d03839cae23c7243accc0ac0a12079d358328bf73ad2e0ebe
    }
    network={
           ssid="myssid2"
           scan_ssid=0
           proto=WPA
           key_mgmt=WPA-PSK
           psk=d89660510d06bbf7691f5296daae36872d697a88876c53db7de91aa85df4f68b
    }
    network={
           ssid="myssid3"
           scan_ssid=0
           proto=WPA
           key_mgmt=WPA-PSK
           psk=d635b33481a13b28a67e8964f58343cb19bc8c85c67cc56ee9bfe0c302914a5f
    }
like image 394
Rolwin Crasta Avatar asked Feb 16 '15 14:02

Rolwin Crasta


People also ask

Where is wpa_supplicant Conf stored?

A sample wpa_supplicant. conf file is installed in /etc for you. It contains a detailed description of the basic supplicant configuration parameters and network parameter descriptions (and there are lots of them) and sample network configuration blocks.

What is ETC wpa_supplicant conf?

conf. wpa_supplicant. conf is a configuration file for wpa_supplicant, a piece of software used to implement WPA and other security protocols that WiFi networks implement. Before continuing on, you should know what kind of security protocol (WPA, WPA2, WPA-PSK, WPA2-PSK, etc) your network requires.

What is Wpa_cli?

Description: The wpa_cli utility is a text-based front-end program for interacting with wpa_supplicant. You can use it to query the current status, change the configuration, trigger events, and request interactive user input.

How do I run WPA supplicant?

You can use wpa_supplicant to connect to hidden networks. To do it you need to edit the configuration file /etc/wpa_supplicant. conf, commenting your current lines and adding the following lines, then run: wpa_supplicant -c /etc/wpa_supplicant. conf -i wlp3s0 and then dhclient wlp3s0.


1 Answers

using wpa_cli you can do this:

1:

wpa_cli remove_network 0

where 0 is the network_id you get after running wpa_cli add_network. It will remove the network and disconnect any interface using it.

Note that the network id is not the order of the network in the file. you can get configured network using wpa_cli list_networks

2:

wpa_cli save_config

This will persist the changes and the corresponding network block will be removed from etc/wpa_supplicant/wpa_supplicant.conf

like image 124
Tychus Avatar answered Sep 22 '22 18:09

Tychus