
How to Connect to Wifi Nmcli? Detailed Step-by-Step Network Setup Guide
Introduction If you have ever worked on a Linux server, Raspberry Pi, or any headless machine without a graphical desktop, you have probably wondered How to Connect to Wifi Nmcli? The answer lies in a powerful command-line tool called nmcli, which is the comma
Introduction
If you have ever worked on a Linux server, Raspberry Pi, or any headless machine without a graphical desktop, you have probably wondered How to Connect to Wifi Nmcli? The answer lies in a powerful command-line tool called nmcli, which is the command-line interface for NetworkManager. Instead of clicking through network settings, nmcli lets you scan, connect, disconnect, and manage wireless networks entirely from the terminal. Whether you are a system administrator configuring remote servers, a developer working on embedded devices, or simply someone who prefers the command line, learning how to use nmcli is an essential skill.
In this detailed step-by-step network setup guide, we will walk through everything you need to know about connecting to Wi-Fi using nmcli. We will cover scanning for networks, connecting to open and secured networks, handling hidden SSIDs, managing saved connections, troubleshooting common errors, and comparing nmcli with other networking tools. By the end of this guide, you will be able to confidently answer the question How to Connect to Wifi Nmcli? for any Linux distribution that uses NetworkManager.
Table of Contents
- Introduction
- What Is nmcli?
- Prerequisites
- Scanning for Available Wi-Fi Networks
- Connecting to an Open Network
- Connecting to a Secured WPA/WPA2 Network
- Connecting to a Hidden Network
- Managing Saved Connections
- Disconnecting and Deleting Connections
- nmcli vs Other Networking Tools
- Troubleshooting Common Issues
- Tips and Best Practices
- Frequently Asked Questions
- Conclusion
What Is nmcli?
nmcli stands for NetworkManager Command Line Interface. NetworkManager itself is a system service that manages network connections on Linux. It handles Ethernet, Wi-Fi, VPNs, and more. The nmcli tool provides a terminal-based way to interact with this service, making it perfect for headless environments, remote SSH sessions, and automated scripts.
Unlike older tools such as iwconfig or wpa_supplicant configured manually, nmcli integrates deeply with NetworkManager, which means your connections are saved, managed, and can be controlled consistently across the system. When someone asks How to Connect to Wifi Nmcli?, they are really asking how to leverage this integration to get online quickly and reliably.
nmcli is available on nearly all modern Linux distributions, including Ubuntu, Debian, Fedora, CentOS, RHEL, Arch Linux, and openSUSE. It comes pre-installed wherever NetworkManager is the default networking backend, which is the case for most desktop and server distributions today.
Prerequisites
Before you begin, make sure the following conditions are met:
- A Linux system with NetworkManager installed and running.
- A wireless network interface (Wi-Fi adapter) present on the machine.
- Root or sudo privileges, since network changes require elevated permissions.
- Basic familiarity with the Linux terminal.
To verify that NetworkManager is running, use the following command:
systemctl status NetworkManager
If it shows active (running), you are good to go. You can also check that nmcli is installed by typing:
nmcli --version
This will print the version number. If the command is not found, install NetworkManager using your package manager. On Debian or Ubuntu, run sudo apt install network-manager. On Fedora or RHEL, run sudo dnf install NetworkManager.
Scanning for Available Wi-Fi Networks
The first step in answering How to Connect to Wifi Nmcli? is discovering which networks are available. nmcli can scan for nearby wireless networks and display them in a clean table.
Run the following command:
nmcli device wifi list
This outputs a table showing the SSID, mode, channel, rate, signal strength, security type, and BSSID of each detected network. If your wireless interface is not active, you may need to bring it up first:
nmcli device set wlan0 managed yes
nmcli radio wifi on
Replace wlan0 with your actual interface name, which you can find using nmcli device status. The radio command ensures the Wi-Fi radio is not soft-blocked. If you see no networks, try rescanning explicitly:
nmcli device wifi rescan
Then list again. Signal strength is shown as a percentage, and the security column tells you whether the network uses WPA, WPA2, WEP, or is open.
Connecting to an Open Network
If the target network has no password, connecting is straightforward. Use the following syntax:
nmcli device wifi connect "SSID_NAME"
For example, if the network is named FreePublicWiFi, you would run:
nmcli device wifi connect "FreePublicWiFi"
nmcli will automatically create a connection profile, activate it, and assign an IP address via DHCP. You can verify the connection with:
nmcli connection show --active
or check your IP address with:
ip addr show wlan0
This simple flow is often the first thing people learn when researching How to Connect to Wifi Nmcli?, and it works reliably for open networks.
Connecting to a Secured WPA/WPA2 Network
Most real-world networks are secured with a password. To connect to a WPA or WPA2 network, you need to provide the password using the password option:
nmcli device wifi connect "SSID_NAME" password "YOUR_PASSWORD"
For example:
nmcli device wifi connect "HomeNetwork" password "s3cr3tP@ss"
nmcli will create a connection profile, store the credentials securely, and activate the connection. If the password is correct, you will be connected within seconds. If authentication fails, nmcli will report an error such as Secrets were required, but not provided or a wrong password message.
For WPA2-Enterprise networks that require a username and password (common in corporate environments), use:
nmcli connection add type wifi con-name "CorpWiFi" ifname wlan0 ssid "CorpSSID"
nmcli connection modify "CorpWiFi" wifi-sec.key-mgmt wpa-eap 802-1x.eap peap 802-1x.identity "your_username" 802-1x.password "your_password"
nmcli connection up "CorpWiFi"
This three-step approach creates the profile, configures enterprise authentication, and brings the connection up.
Connecting to a Hidden Network
Hidden networks do not broadcast their SSID, so they will not appear in the scan list. To connect to one, you must specify the SSID manually and set the hidden flag:
nmcli device wifi connect "HiddenSSID" password "YOUR_PASSWORD" hidden yes
If the network is open but hidden, omit the password:
nmcli device wifi connect "HiddenSSID" hidden yes
Because the network is not broadcasting, nmcli cannot verify the SSID exists nearby, so make sure you type it exactly, including case sensitivity. This is a common stumbling block when people first explore How to Connect to Wifi Nmcli?, so double-check spelling and capitalization.
Managing Saved Connections
One of the great advantages of nmcli is that it saves connection profiles. You can list all saved connections with:
nmcli connection show
To view details of a specific connection:
nmcli connection show "HomeNetwork"
To activate a previously saved connection:
nmcli connection up "HomeNetwork"
To deactivate it:
nmcli connection down "HomeNetwork"
You can also modify connection properties. For example, to change the saved password:
nmcli connection modify "HomeNetwork" wifi-sec.psk "newpassword"
Or to set a connection to auto-connect on boot:
nmcli connection modify "HomeNetwork" connection.autoconnect yes
These profiles are stored in /etc/NetworkManager/system-connections/, so they persist across reboots.
Disconnecting and Deleting Connections
To disconnect from the current Wi-Fi without deleting the profile, use:
nmcli device disconnect wlan0
This brings the interface down but keeps the saved profile. If you want to permanently remove a saved connection, use:
nmcli connection delete "OldNetwork"
This deletes the profile file from disk. Be careful, as this action cannot be undone without recreating the profile. These operations are part of the complete picture of How to Connect to Wifi Nmcli?, because managing connections includes knowing how to remove them cleanly.
nmcli vs Other Networking Tools
There are several tools for managing Wi-Fi on Linux. Here is a comparison to help you understand where nmcli fits:
| Tool | Interface | Persistence | Best For | Learning Curve |
|---|---|---|---|---|
| nmcli | Command line | Saves profiles automatically | Headless servers, scripts, admins | Moderate |
| nmtui | Text UI (ncurses) | Saves profiles | Interactive terminal users | Low |
| wpa_supplicant | Config file + daemon | Manual config files | Minimal systems, embedded | High |
| iwconfig | Command line | Not persistent | Quick ad-hoc checks | Low |
| NetworkManager GUI | Graphical | Saves profiles | Desktop users | Very low |
As you can see, nmcli strikes a balance between power and usability. It is more scriptable than nmtui, more persistent than iwconfig, and more user-friendly than raw wpa_supplicant configuration.
Troubleshooting Common Issues
Even with a clear guide on How to Connect to Wifi Nmcli?, you may run into problems. Here are common issues and fixes:
Device Not Managed
If nmcli device status shows your Wi-Fi interface as unmanaged, NetworkManager is not controlling it. Edit /etc/NetworkManager/NetworkManager.conf and ensure managed=true under the [ifupdown] section, then restart NetworkManager:
sudo systemctl restart NetworkManager
Wi-Fi Radio Blocked
If the radio is soft-blocked, run:
rfkill unblock wifi
Then turn the radio on with nmcli radio wifi on.
Wrong Password or Authentication Failure
Double-check the SSID spelling and password. Passwords are case-sensitive. You can also delete the failed profile and recreate it:
nmcli connection delete "FailedNetwork"
nmcli device wifi connect "FailedNetwork" password "correctpassword"
DHCP Failure
If you connect but get no IP address, check that DHCP is enabled on the connection:
nmcli connection modify "YourNetwork" ipv4.method auto
nmcli connection up "YourNetwork"
DNS Not Resolving
Set DNS servers manually if needed:
nmcli connection modify "YourNetwork" ipv4.dns "8.8.8.8 1.1.1.1"
nmcli connection up "YourNetwork"
Tips and Best Practices
- Always quote SSIDs and passwords that contain spaces or special characters.
- Use
nmcli -t -f SSID,SIGNAL,SECURITY device wifi listfor a terse, script-friendly output. - Enable autoconnect for networks you use regularly so they reconnect after reboot.
- Store connection profiles in version control if you manage many machines, by backing up
/etc/NetworkManager/system-connections/. - Use
nmcli general statusto quickly check overall connectivity state. - For automation, prefer
nmcli connection upovernmcli device wifi connectbecause it uses saved profiles. - Test connectivity after connecting with
ping -c 4 8.8.8.8andping -c 4 google.com. - Keep NetworkManager updated to benefit from security patches and bug fixes.
Following these practices will make your experience smoother every time you revisit How to Connect to Wifi Nmcli?.
Frequently Asked Questions
Can I use nmcli without sudo?
Some read-only commands like listing networks work without sudo, but connecting, disconnecting, and modifying connections require root privileges. You can configure PolicyKit rules to allow certain users to manage connections without full sudo, but by default sudo is needed.
Does nmcli work on all Linux distributions?
nmcli works on any distribution that uses NetworkManager. Most major distributions do, including Ubuntu, Debian, Fedora, CentOS, RHEL, Arch, and openSUSE. Minimal distributions like Alpine may use other tools by default.
How do I find my Wi-Fi interface name?
Run nmcli device status and look for the device with type wifi. Common names include wlan0, wlp2s0, or wlo1.
Can nmcli connect to 5 GHz networks?
Yes, as long as your Wi-Fi adapter supports 5 GHz. nmcli does not restrict bands; it connects to whatever networks the hardware and driver expose.
How do I make a connection the default?
Set its priority higher than others using nmcli connection modify "YourNetwork" connection.autoconnect-priority 10. Higher numbers are preferred.
Is the password stored securely?
By default, passwords are stored in the connection profile with permissions restricted to root. For stronger security, you can configure NetworkManager to use a secret agent or keyring, though this is more common on desktop systems.
Conclusion
By now, you should have a complete understanding of How to Connect to Wifi Nmcli?. We started with the basics of what nmcli is and why it matters, then walked through scanning networks, connecting to open, secured, and hidden networks, managing and deleting profiles, comparing nmcli with other tools, troubleshooting common issues, and following best practices. The key commands to remember are nmcli device wifi list to scan, nmcli device wifi connect "SSID" password "PASS" to connect, nmcli connection show to manage profiles, and nmcli connection up to activate saved networks.
nmcli is a versatile, scriptable, and reliable tool that belongs in every Linux user’s toolkit. Whether you are configuring a headless Raspberry Pi, managing a fleet of servers, or just prefer the terminal, mastering nmcli will save you time and headaches. Bookmark this guide, practice the commands on a test machine, and soon connecting to Wi-Fi from the command line will feel second nature.