I need to write a shell script which connects to one of the two available wi-fi connections. One is a un secure connection and the other is secure connection.
My question has 2 parts-
-
How to connect to the un-secure (un-encrypted and no password required) connection from command line (or by executing a shell script) when I'm connected to the secure connection?
I followed the steps in http://www.ubuntugeek.com/how-to-troubleshoot-wireless-network-connection-in-ubuntu.html for in-secure connection. I put all the commands in a script and executed it (I made sure that interface name and essid are correct)
sudo dhclient -r wlan0 sudo ifconfig wlan0 up sudo iwconfig wlan0 essid "UAPublic" sudo iwconfig wlan0 mode Managed sudo dhclient wlan0
But nothing happens: I'm not disconnected from the current network and connected to the new one.
-
When I want to connect to the secure wi-fi network, I understand from https://askubuntu.com/a/138476/70665 that I need to use
wpa_supplicant
.
But I enter a lot of details in the interface when I connect via UI- security : wpa and wpa2 enterprise
- Authentication : PEAP
- CA certificate : Equifax…
- PEAP version : automatic
- inner authentication : MSCHAPv2
- username :
- password :
How to use wpa_supplicant to mention all these details in the command line? The conf file
network={
ssid="ssid_name"
psk="password"
}
doesn't work for me.
Best Answer
I'm assuming you're using Ubuntu Desktop as you didn't specify otherwise.
You can create a wireless network configuration that will be managed by Network Manager by creating files in
/etc/NetworkManager/system-connections
. Look at existing files to see how the format looks like.Once the connection is created, you can use the
nmcli
command to manage NetworkManager from the command line, doing things such as enabling, disabling and querying connections.Incidentally, the System Testing tool (checkbox) has a script that does exactly this: creates a connection and enables it, with parameters that you supply on the command line.
For instance, this creates a connection to the open "duck" network:
This will create a connection to a network using WPA2 security, with "wings" password:
The script is written in Python so it should be easy for you to look at and adapt to your needs.
The script's help says this: