How to Connect to Wi-Fi Using `wpa_supplicant` on Arch Linux
wpa_supplicant
on Arch Linux.Categories:
5 minute read
Arch Linux is a lightweight and flexible Linux distribution aimed at more experienced users who enjoy building their system from the ground up. When it comes to networking, Arch gives you full control — including the ability to connect to Wi-Fi networks manually without relying on graphical utilities or network managers.
One of the most powerful tools for managing wireless networks in a command-line environment is wpa_supplicant
. This article provides a comprehensive, step-by-step guide on how to connect to a Wi-Fi network using wpa_supplicant
on Arch Linux.
Why Use wpa_supplicant
?
Before diving in, it’s helpful to understand why one might choose wpa_supplicant
over a GUI-based solution:
- Minimalist Setup: Ideal for servers, headless systems, or minimal desktop environments.
- Full Control: You configure and control every aspect of the connection.
- No Bloat: Avoid installing full network managers like NetworkManager or ConnMan.
- Learning Opportunity: You gain a deeper understanding of how Linux handles wireless networking.
Prerequisites
Before starting, make sure your system meets the following requirements:
1. A Wireless Interface
Run the following to list your network interfaces:
ip link
Wireless interfaces are usually named wlan0
, wlp2s0
, or something similar, depending on your hardware and naming scheme.
2. Required Packages
Ensure the necessary packages are installed:
sudo pacman -Syu wpa_supplicant wireless_tools dialog iw
Explanation of each package:
wpa_supplicant
: The main daemon that handles WPA/WPA2 authentication.wireless_tools
: Utilities likeiwconfig
.dialog
: Provides text-based GUI elements (used bywifi-menu
).iw
: Modern utility for configuring wireless devices.
Step-by-Step Guide to Connect Using wpa_supplicant
Step 1: Bring Up the Wireless Interface
First, check if your wireless device is recognized and enabled:
ip link show
If your wireless interface (say, wlp2s0
) is down, bring it up:
sudo ip link set wlp2s0 up
Use your interface name in place of wlp2s0
.
Step 2: Scan for Available Networks
Use iw
to scan for available Wi-Fi networks:
sudo iw dev wlp2s0 scan | less
This command returns a lot of data, but you’re looking for lines like:
SSID: YourNetworkName
Note the SSID of the network you want to connect to.
Step 3: Create a WPA Configuration File
You’ll need a configuration file for wpa_supplicant
. You can generate one using wpa_passphrase
:
wpa_passphrase "YourNetworkName" "YourPassword"
Example:
wpa_passphrase "HomeWiFi" "StrongPass123"
This will output:
network={
ssid="HomeWiFi"
#psk="StrongPass123"
psk=7e0c9a60d82b2f0000d0b3df87fcfd49f84e27e0dfebf2ddfd019e67c4b8cbfc
}
Redirect the output to a file:
wpa_passphrase "HomeWiFi" "StrongPass123" | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf
Step 4: Start wpa_supplicant
Now you can start wpa_supplicant
with the correct options. The basic syntax is:
sudo wpa_supplicant -B -i wlp2s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Explanation:
-B
: Run in the background.-i
: Interface to use.-c
: Path to the configuration file.
Check the output of:
sudo journalctl -u wpa_supplicant
To ensure the connection process started correctly.
Step 5: Obtain an IP Address
Once authenticated, you need to get an IP address using a DHCP client:
sudo dhcpcd wlp2s0
Alternatively, you can use:
sudo dhclient wlp2s0
Depending on which DHCP client you prefer (make sure it’s installed).
To verify connectivity:
ping archlinux.org
If you receive replies, you’re online!
Optional: Run as a Systemd Service
If you want wpa_supplicant
to connect automatically at boot, you can enable it as a systemd service.
Step 1: Create a Service File (Optional)
You can use the built-in service file:
sudo systemctl enable wpa_supplicant@wlp2s0.service
And start it with:
sudo systemctl start wpa_supplicant@wlp2s0.service
This will automatically read the default config file at /etc/wpa_supplicant/wpa_supplicant.conf
.
Step 2: Enable DHCP at Boot
Also enable a DHCP client to get an IP address automatically:
sudo systemctl enable dhcpcd@wlp2s0.service
Or if you’re using systemd-networkd
, configure that instead.
Troubleshooting
Problem: Could not read interface
or No such device
Make sure your interface is listed and brought up using:
ip link set wlp2s0 up
If still not found, you may need firmware drivers for your Wi-Fi chip. Check the output of:
dmesg | grep firmware
Install firmware packages such as linux-firmware
or specific ones like broadcom-wl
.
Problem: No IP Address After Connecting
After wpa_supplicant
succeeds, make sure you’ve requested an IP:
sudo dhcpcd wlp2s0
Or check ip a
to see if an address was assigned.
Problem: Authentication Fails
- Double-check your SSID and password.
- Ensure no typos in the
wpa_supplicant.conf
. - Look for errors in:
sudo journalctl -xeu wpa_supplicant
Advanced Options
Using a Temporary Config File
You don’t have to save a config to disk. This is useful for testing:
wpa_passphrase "MySSID" "MyPassword" > temp.conf
sudo wpa_supplicant -B -i wlp2s0 -c temp.conf
Open Networks (No Password)
For open networks, create a minimal config like:
network={
ssid="OpenWiFi"
key_mgmt=NONE
}
Save it and use it with wpa_supplicant
.
Wrapping Up
Connecting to Wi-Fi using wpa_supplicant
on Arch Linux may seem intimidating at first, but it’s a powerful and transparent method that grants full control over your system’s network behavior. Whether you’re managing a headless device or simply prefer command-line tools, mastering wpa_supplicant
is a valuable skill for any Arch Linux user.
To recap:
- Bring up the interface.
- Scan for networks.
- Create a
wpa_supplicant
config. - Start
wpa_supplicant
. - Obtain an IP address via DHCP.
- Optionally, automate the process with systemd services.
Arch’s philosophy of simplicity and user-centric control shines through in how it handles networking. By learning to use wpa_supplicant
, you’re aligning with the Arch way — and becoming a more knowledgeable Linux user in the process.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.