To connect your Raspberry Pi to Wi-Fi via the terminal, you can follow these steps:
1. **Identify your Wi-Fi interface:**
First, check the name of your wireless interface. It's usually `wlan0` or `wlan1`.
```bash
ip a
```
Look for an interface starting with `wl` (e.g., `wlan0`).
1. **Scan for available Wi-Fi networks (optional but helpful):**
You can see available networks and their SSIDs (network names) using:
```bash
sudo iwlist wlan0 scan | grep ESSID
```
(Replace `wlan0` with your actual interface name if different).
1. **Edit the `wpa_supplicant.conf` file:**
This file stores your Wi-Fi network configurations.
```bash
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
```
Scroll to the bottom of the file and add the following block, replacing `YOUR_NETWORK_NAME` with your Wi-Fi SSID and `YOUR_PASSWORD` with your Wi-Fi password:
```
network={
ssid="YOUR_NETWORK_NAME"
psk="YOUR_PASSWORD"
}
```
* **For hidden networks**, add `scan_ssid=1` inside the `network` block:
```
network={
ssid="YOUR_NETWORK_NAME"
psk="YOUR_PASSWORD"
scan_ssid=1
}
```
* **For open (unsecured) networks**, use this format:
```
network={
ssid="YOUR_NETWORK_NAME"
key_mgmt=NONE
}
```
Press `Ctrl+X`, then `Y` to save, and `Enter` to confirm the filename.
1. **Reboot or restart networking services:**
To apply the changes, you can either reboot your Raspberry Pi:
```bash
sudo reboot
```
Or, restart the networking service:
```bash
sudo systemctl daemon-reload
sudo systemctl restart dhcpcd.service
```
(Note: `dhcpcd.service` is commonly used for network configuration on Raspberry Pi OS. If you're using a different setup, the service name might vary.)
1. **Verify the connection:**
After rebooting or restarting services, check if your Raspberry Pi has obtained an IP address:
```bash
ip a show wlan0
```
Look for an `inet` address under your `wlan0` interface. You can also try pinging a website:
```bash
ping google.com
```
If you see replies, your Raspberry Pi is connected to the internet.