Connect Raspberry Pi To WiFi Via The Command Line

Using Ethernet cable to connect with Internet is too old fashion and does not provide mobility. So the best option we have is to connect Raspberry Pi To WiFi network. This article will help you connect your Raspberry Pi to Wifi network via the command line in your Raspberry Pi. We assume you have already setup your Raspberry Pi, if not then visit this link if you want to headless setup Raspberry Pi in matter of time.

raspberry-pi-wifi-dongle

This is very easy trick and has only a few steps (commands). So let’s get started.

Step 1: Turn Raspberry Pi ON and start it’s terminal or any terminal which is connected to the Raspberry Pi (If you are using it headlessly).

SSH Connection to Raspberry Pi and Macbook

Step 2: Enter the command given below in the command line to list all available WiFi networks to find your network’s ESSID.

sudo iwlist wlan0 scan

Wifi Network List

Step 3: Find or trace your network’s ESSID by find option in terminal or manually to copy it so there will be no chances of failure.

Step 4: Open the wpa-supplicant configuration file in nano.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add network information to connect to Wifi in Raspberry Pi

Step 5: Add the code given below at the end of the file with correct information.

network={
    ssid="testing"
    psk="testingPassword"
}

Step 6: Now press Ctrl + X Exit the File.

Step 7: It will ask to save the changes or not, Press to save the changes in the file. Then Hit Enter/Return.

Step 8: That’s all. Your work is over.

After few seconds, wpa-supplicant file will notice some changes have occurred, so it will try to connect to the network.

NOTE: Don’t forget to attach WiFi Connector to your Raspberry Pi else it won’t be able to connect to WiFi.

If it is not getting connected and you want to force connect, then reboot your Raspberry Pi with sudo reboot command in the command line.

If Raspberry Pi is still not connected To WiFi network, check your password and ESSID are correct.

If you have any query related to this article then feel free to ask in the comment section. We will be glad to help you out.

Thank You & Stay Techie…