First, forget about solutions using
iwconfig (which does not support WPA) or
wpa_supplicant. They are outdated.
Modern (post-2010) Linux distributions use
NetworkManager to manage network connections.
nmcli is the command line interface to
This tutorial assumes that your WiFi adapter has been properly driven by the Linux kernel.
- Make sure NetworkManager is running (It should be on if you boot into a desktop environment. But it may not be running by default if you are in the non-GUI mode of Linux.)
systemctl start NetworkManager
- Scan for available WiFi networks
$ nmcli device wifi list
You can pipeline it with the
lesscommand if you have a long list of WiFi access points (APs).
- Connect to a WiFi network for the first time (If this is not the first time, jump to step 3).
sudo nmcli device wifi connect NETWORK_SSID
NETWORK_SSIDis the ID of the network.
If the network is password-protected, you can pass the password verbatim like this:
sudo nmcli device wifi connect NETWORK_SSID password "NETWORK-PASSWORD"
Or, if you prefer not to leave your password in your shell history, you can use the
--askflag to be prompt to enter a password.
sudo nmcli device wifi connect NETWORK_SSID --ask
The information of each network (called “connection” in NetworkManager’s terminology), including the password, is stored into a configuration file under
/etc/NetworkManager/system-connections/. That’s why you only needed to do this step once, when you initially connect to a WiFi. Otherwise,
nmcliwill create duplicates for you.
- To connect to a network that was previously connected to, simply
nmcli con up NETWORK_SSID
- Check your connection. You can simply check your connections by
- Disconnect from a WiFi, if you need to:
nmcli con down NETWORK_SSID
- Auto-start NetworkManager at system book (only for non-GUI boot)
NetworkManager is a GUI program and is usually started when the desktop environment starts. What if you Linux box is configured to boot into non-GUI mode as in a server?
Simply enable NetworkManager in
sudo systemctl enable NetworkManager
You can use
iwconfig (for wireless only) to identify all your network interfaces. Then use
iwlist to scan to know more information of the networks available around your.
The output is
lo no wireless extensions.
wlp0s20f3 IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=22 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
As you can see,
wlp0s20f3 is the wireless adapter on my computer. Then I just need to run
sudo iwlist wlp0s20f3 scan
to find out detailed information about WiFi networks available around me.