Connecting to Wi-Fi from the Raspberry Pi Console

Connecting to Wi-Fi from the Raspberry Pi Console

Connecting to Wi-Fi from the Raspberry Pi Console

 Hello everyone, in this article I will explain how to connect your Raspberry device to a Wi-Fi network via the console, that is, via SSH. Let's get started.

First, we need to open the settings panel, for this enter the following command.

sudo raspi-config

After entering the command, from the System settings section go to Internet settings and change the country location.

Select the country where you live or its relevant location information.


Connecting to Wi-Fi from the Raspberry Pi Console

Connecting to Wi-Fi from the Raspberry Pi Console


Connecting to Wi-Fi from the Raspberry Pi Console

After selecting the country you are in, when you come to the "<ok>" section, a screen like below will appear. This means the process is complete.

Connecting to Wi-Fi from the Raspberry Pi Console

After this, a page requiring you to enter the "SSID" will come up. Here, close the page without entering any information.

While closing, it will ask whether you want to restart the device—absolutely let it restart the device.

After your device has restarted, you can see the Wi-Fi devices in the area with the following command.

sudo iwlist wlan0 scan

After entering the command, all networks in the environment will appear as shown below.

sudo iwlist wlan0 scan

After getting the SSID of the network you want to connect to, you now need to edit the file named wpa-supplicant. To open the wpa-supplicant file with the Nano editor, enter the command below.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

After entering the command, enter the Wi-Fi network information you want to connect to in the opened file.

network={
    ssid="Network Name or SSID"
    psk="Network Password"
}

Replace the places in the code above with your own network's information and insert it into the file you opened.


Wifi Information

To save, press ctrl + o, and then to exit, press ctrl + x. After closing, when you restart your device, it will automatically connect to the Wi-Fi network.

Note: If you want to add more than one network and give priority to networks, you can use it as follows.

network={
    ssid="net1"
    psk="net1Password"
    priority=1
    id_str="netName"
}

network={
    ssid="net2"
    psk="net2Password"
    priority=2
    id_str="net2Name"
}

Here we have added two networks and with "ssid" we selected the network to be connected to; then we entered their passwords with "psk"; with "priority" we selected which one to connect first if both networks are seen at the same time. With "id_str", we entered the names we want to see when listing saved networks.

This article ends here. If you have any questions, feel free to ask in the comments section below. Have a good day.