Connecting to a wireless network via a terminal in Debian or its derivatives (for example, Ubuntu Server, Raspberry Pi OS) may seem like a daunting task for beginners. However, this skill is indispensable when a graphical interface is not available—for example, on a server without GUI, in a restored system or when configuring remotely via SSHUnlike Windows or macOS, where connecting to Wi-Fi is intuitive, Linux requires knowledge of specific commands and utilities.
In this article we will look at three main methods: using NetworkManager (through nmcli), manual tuning with wpa_supplicant and low-level commands iwconfig/ifconfigEach method has its advantages: nmcli easier for everyday tasks, wpa_supplicant more reliable for servers, and manual commands will help in emergency situations. We will also cover common errors (for example, "Device not managed") and ways to eliminate them.
Before you begin, make sure your Wi-Fi adapter is supported by the Linux kernel. To do this, run the command lspci | grep -i wireless (for PCI devices) or lsusb (for USB adapters). If the adapter is not detected, you may need to install proprietary drivers (for example, for chips) Broadcom).
1. Connecting via NetworkManager (nmcli)
NetworkManager — a standard network management tool in most Debian distributions. The utility nmcli allows you to manage connections from a terminal without a graphical interface. This method is suitable for desktop systems and servers with NetworkManager.
To connect to Wi-Fi:
- Check NetworkManager status:
sudo systemctl status NetworkManagerIf the service is not active, start it:
sudo systemctl start NetworkManager - Get a list of available networks:
nmcli device wifi listOr refresh the list if the networks are not displayed:
nmcli device wifi rescan - Connect to the network:
nmcli device wifi connect "NETWORK_NAME" password "PASSWORD"Replace
NETWORK_NAMEAndPASSWORDfor up-to-date data. For hidden networks, add a flaghidden yes.
If the connection was successful, check the status:
nmcli connection show
Or look at the IP address:
ip a show wlan0
Adapter enabled (rfkill unblock wifi)|NetworkManager service active|Networks displayed in nmcli device wifi list|Password entered correctly-->
⚠️ Attention: If the teamnmcli device wifi listreturns an error"Error: Device 'wlan0' is not active", check if the adapter is disabled programmatically by the commandrfkill listUnlock it withrfkill unblock wifi.
2. Manual connection with wpa_supplicant
Utility wpa_supplicant — a more flexible and reliable way to connect to Wi-Fi, especially on servers without NetworkManagerIt supports modern safety standards (WPA3, 802.1X) and allows you to save configurations in a file /etc/wpa_supplicant/wpa_supplicant.conf.
Setup instructions:
- Install
wpa_supplicant(if not installed):sudo apt update && sudo apt install wpa-supplicant - Generate a configuration file:
wpa_passphrase "NETWORK_NAME" "PASSWORD" | sudo tee /etc/wpa_supplicant/wpa_supplicant.confThis command will create an encrypted file with settings.
- Connect to the network:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.confFlag
-Bruns the process in the background. - Obtain an IP address via DHCP:
sudo dhclient wlan0
To make the connection automatically at boot, add to /etc/network/interfaces:
auto wlan0iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
What to do if wpa_supplicant does not connect?
If after launch wpa_supplicant The connection is not established, check the logs:
journalctl -u wpa_supplicant -fCommon causes:
- Incorrect password or network name (check the case!).
- Unsupported security standard (eg. WPA3-Enterprise requires additional parameters in the config).
- Adapter lock (rfkill list).
| Error | Possible cause | Solution |
|---|---|---|
Failed to initialize driver |
The Wi-Fi adapter driver is not loaded. | Check it out dmesg | grep wlan, install proprietary drivers |
No network configuration found |
File wpa_supplicant.conf empty or missing |
Generate the config again with wpa_passphrase |
Association with AP failed |
Incorrect password or security standard | Check your password, add key_mgmt=WPA-PSK in the config |
DHCP discovery failed |
IP address is not assigned | Launch dhclient wlan0 manually or check your router settings |
3. Low-level connection with iwconfig and ifconfig
If NetworkManager And wpa_supplicant are not available, you can connect to an open network or a network with WEP- encryption (not recommended!) using basic utilities iwconfig And ifconfigThis method is appropriate for minimalistic systems or for diagnostics.
Warning: WEP encryption is outdated and insecure. Use this method only for testing or connecting to open networks.
- Check the wireless interface name:
iwconfigUsually it is
wlan0orwlp3s0. - Connect to an open network:
sudo iwconfig wlan0 essid "NETWORK_NAME" key off - Get an IP address:
sudo dhclient wlan0 - For WEP network (not recommended!):
sudo iwconfig wlan0 essid "NETWORK_NAME" key "PASSWORD_IN_HEX"The password must be in hex format (For example,
1234567890→31323334353637383930).
⚠️ Attention: TeamsifconfigAndiwconfigare considered obsolete in newer distributions. It is recommended to use them instead.ipAndiwFor example, to view networks:sudo iw dev wlan0 scan | grep SSID
sudo apt install wireless-tools
However, for modern systems it is better to use iw from the package iw (already pre-installed in most distributions).-->
4. Diagnosing connection problems
If your Wi-Fi isn't connecting, start by checking the following:
- 🔍 Is the adapter turned on? Check with
rfkill listIf the adapter is blocked, unlock it:rfkill unblock wifi - 📡 Does the system see networks? Perform a scan:
sudo iw dev wlan0 scan | grep SSIDIf there are no networks, the problem may be in the driver or antenna.
- 🔑 Is the password correct? Make sure your password is entered correctly (case-sensitive!). To test, create a test config:
wpa_passphrase "NETWORK_NAME" "PASSWORD" - 🔧 Is the driver loaded? Check kernel logs:
dmesg | grep wlanIf there are errors of the type
"firmware missing", install proprietary drivers (for example, for Broadcom).
If the problem persists, check the logs. wpa_supplicant:
journalctl -u wpa_supplicant -b
Or check the network status:
ip link show wlan0
1) Lack of/incorrect installation of drivers.
2) Adapter lock (rfkill).
3) Errors in configuration files (wpa_supplicant.conf or /etc/network/interfaces).-->
5. Automatic connection on boot
To connect Wi-Fi automatically after a reboot, set up autostart wpa_supplicant And dhclient:
- Edit
/etc/network/interfaces:
Note: The password must be in hex format (generate it usingauto wlan0iface wlan0 inet dhcp
wpa-ssid NETWORK_NAME
wpa-psk PASSWORDwpa_passphrase). - Alternatively, for
systemd:Create a service
/etc/systemd/system/wpa_supplicant.service:[Unit]Description=WPA supplicant
After=sys-subsystem-net-devices-wlan0.device
[Service]
Type=simple
ExecStart=/sbin/wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -D nl80211,wext
ExecStop=/sbin/killall wpa_supplicant
[Install]
WantedBy=multi-user.targetThen activate it:
sudo systemctl enable wpa_supplicant
For NetworkManager it is enough to mark the connection as automatic:
nmcli connection modify "CONNECTION_NAME" connection.autoconnect yes
6. Security: How to protect your connection
When setting up Wi-Fi via a terminal, it is important to ensure the security of configuration files:
- 🔒 Access rights: File
/etc/wpa_supplicant/wpa_supplicant.confshould be accessible only by root:sudo chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf - 🛡️ Use modern standards: Avoid WEP And WPA — set up WPA2-PSK or WPA3. In the config
wpa_supplicantplease specify:proto=RSNkey_mgmt=WPA-PSK
pairwise=CCMP - 🔄 Update your software regularly: Drivers and utilities (eg
wpa_supplicant) may contain vulnerabilities. Update them with the command:sudo apt update && sudo apt upgrade - 📛 Hide SSID (optional): If the network should not be visible to everyone, add the following setting to the router configuration
hide_ssid=1and connect with the flagscan_ssid=1Vwpa_supplicant.
Warning: Never store passwords in cleartext in scripts or configuration files with broad access rights. Use wpa_passphrase to generate hashed versions.
FAQ: Frequently Asked Questions
My Wi-Fi adapter isn't detected. What should I do?
First, check if the adapter is detected by the system:
lspci -knn | grep -iA3 net
If the adapter is listed but does not work, install the driver. For Broadcom:
sudo apt install firmware-b43-installer
For Realtek a driver from the repository may be required non-freeAdd it to /etc/apt/sources.list:
deb http://deb.debian.org/debian bookworm main contrib non-free
How to connect to Wi-Fi without a password (open network)?
For an open network with wpa_supplicant create a config:
network={ssid="NETWORK_NAME"
key_mgmt=NONE
}
Then connect:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
sudo dhclient wlan0
Through nmcli:
nmcli device wifi connect "NETWORK_NAME"
Why doesn't Wi-Fi connect automatically after a reboot?
The reasons may be as follows:
NetworkManagerDoesn't save settings. Check:nmcli connection showIf the connection is missing, recreate it with the flag
autoconnect yes.- Service
wpa_supplicantwon't start. Check:systemctl status wpa_supplicantActivate autostart:
sudo systemctl enable wpa_supplicant - IN
/etc/network/interfacesIncorrect settings. Example of a correct configuration:auto wlan0iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Is it possible to connect to Wi-Fi via Terminal on Android (Termux)?
IN Termux Wi-Fi connectivity via the terminal is limited due to Android security. However, you can:
- Use
termux-wifi-scaninfoto browse networks (requires permission). - Connect via
adbfrom PC:adb shell svc wifi enableadb shell am start -a android.settings.WIFI_SETTINGS - Install
tsu(Termux SU) to work withwpa_supplicanton rooted devices.
Important: On non-rooted devices, direct access to Wi-Fi via the terminal is blocked.
How to change the MAC address of a Wi-Fi adapter before connecting?
To change the MAC address (spoofing), run:
- Disable the interface:
sudo ip link set wlan0 down - Change MAC (for example to
00:11:22:33:44:55):sudo ip link set wlan0 address 00:11:22:33:44:55 - Enable the interface:
sudo ip link set wlan0 up
Warning: MAC address spoofing can violate network usage rules (for example, on corporate or public Wi-Fi).