Connecting to WIFI via the terminal in Linux
I have been searching for a solution to this issue for quite some time. Even though it’s a simple task, linux can sometimes make it a hassle. In Stackoverflow, I found the following solution for WPA-protected wifi access points.
I’m assuming the name of the AP to be foo
and the password to be bar
, and the wifi interface to be wlan0
Create a WPA config file for your access point. This stores all details of the connection.
wpa_passphrase foo > wpa_foo.conf
You will be prompted for a password. Type
bar
A file named
wpa_foo.conf
will be created. Move to/etc/
for security reasonsThe 4th line of the file will contain the password in plain text (but it’s commented). You can remove it for security.
Now, connect to the wifi using the following command
wpa_supplicant -Dwext -B -iwlan0 -c/etc/wpa_foo.conf
Refresh
dhclient
dhclient -r
Ask for a new IP address
dhclient wlan0
Using this method, you should be able to connect, but I’ve found this to be unreliable. I’ve found another solution which uses the CLI of Network Manager
. Keep it in mind that this might not be available in all versions of Linux. But this quite stable and simple and a one-liner.
nmcli d wifi connect foo password bar ifname wlan0
Enjoy.