Raspberry Pi

How to Connect Raspberry Pi to WiFi Using Terminal

WiFi is important for any system, including the Raspberry Pi as well, since it allows users to perform various features like online chatting, web search, installing applications, and others. Further, most of the tasks perform on Raspberry Pi system easily be done through terminal. Thus, if you are looking for a way to connect your Raspberry Pi to WiFi through terminal, you should follow this guide as this will also help you in connecting the WiFI on Raspberry Pi lite version.

Let’s start!

How to Connect Raspberry Pi to WiFi by Using a Terminal

To connect Raspberry Pi to WiFi using the terminal, follow the below-mentioned steps:

Step 1: Check the Available Networks

Before connecting to WiFi if you want to check all the available networks in our area, use the below-mentioned command

 $ sudo iwlist wlan0 scan

Step 2: Open the Configuration File

To configure the WiFi network, we need to create a “wpa_suuplicant .conf” file and for that follow the below-mentioned command:

 $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

By using the above command a blank config file will appear on the screen.

Step 3: Configuring the File

Now, finally it is time to configure the .conf file according to the available network. For configuration, at the top of the file, add the country code and network details as shown below:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

country=<country code like “US” for USA>

 

network={

ssid="<Wifi-Network-Name>"

scan_ssid=1

psk="<Password>"

key_mgmt=WPA-PSK

}

 

 

Note: Remember that “country”, “ssid, and “psk” will be set according to user requirements.

Now, rress the keys “Ctrl + X” and then “Y” to save the file. Finally, press “Enter” to get back to the terminal.

Just like above, multiple networks can also be added to the system so in case if one network is not working fine it automatically gets connected to another one without bothering a user. To add more than 1 network you can just simply copy the above network code (with the credentials of the second network) below the first network’s credential code.

network={

ssid="<Wifi-Network-Name>"

scan_ssid=1

psk="<Password>"

key_mgmt=WPA-PSK

}

Step 4: Reboot

It is always recommended to reboot the system after configuring the WiFi network so that the changes can successfully be applied. To reboot, follow the below mentioned-command

 $ sudo reboot

Step 5: Verifying Network

Now to verify the network, we will check the network connection and for that follow the below command

$ ifconfig wlan0

Check the IP address written in front of inet to verify the network.

That’s it for this guide!

Conclusion

To connect Raspberry Pi to WiFi using a terminal, the user simply has to open the terminal first. Afterward, he/she has to enter the command to open the conf file, and then add the network credentials inside the file including the ssid, password and location. After saving the changes, he/she must reboot the system to ensure Raspberry Pi is connected to the WiFi network.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.