How to connect WiFi from Terminal

We are getting a lot of PMs about how to connect WiFi using Terminal, or specifically wpa_supplicant utility. Since there can be confusions in following online tutorials to do the same here is a step-by-step tutorial for you to follow on the lab exercise 1 and 2.

0. Stop monitor-mode

airmon-ng stop wlan0mon


iwconfig wlan0 mode managed

1. Scan the wireless network (Optional)

iwlist scan wlan0 | grep "rootsh3ll Labs"

2. Create a wpa_supplicant configuration file

wpa_passphrase "rootsh3ll Labs" YourWiFiPassword > wpa.conf

:information_source: Note that we used double quotes around SSID “rootsh3ll Labs” as there’s a space in the name. Without the quotes wpa_passphrase would assume rootsh3ll to be the SSID and Labs to be the password as “space” would act as a delimiter for the shell.

To prevent that you can wrap the desired text inside of quotes or use an escape character to bypass the delimiter.

ex: wpa_passphrase rootsh3ll\ Labs YourWiFiPassword > wpa.conf. We used backslash as an escape character. Learn more about escape characters here

3. Connect to the Access Point

wpa_supplicant -D nl80211 -i wlan0 -c wpa.conf

NOTE: -D switch tells wpa_supplicant to use the driver nl80211. NL80211, not N(one)80211. Followed by -i (interface) and -c (configuration file).

This will establish a connection between your device and the access point.

Next you need an IP address for your device to become a part of the wireless subnet.

4. Request IP Address

dhclient wlan0

DhClient is a utility in linux systems that requests an IP address on your desired interface via DHCP, automatically.

You can verify wlan0 got an IP address via DHCP with ifconfig wlan0

Now you have IP-level connectivity to the wireless subnet. Start scanning and pwning the devices!

All the best for your career and to the hacker in you!

1 Like