How to Connect Wi-Fi from Linux Terminal Using Nmcli Command?

If you are a Linux user and wish to connect to a Wi-Fi network from a terminal, it may seem intimidating at first, but it is actually a simple process using the nmcli command. This article will guide you through the steps of connecting Wi-Fi from a Linux terminal using nmcli commands in a clear and easy-to-understand way.

Prerequisites

First, check the name of your network device by running the following command

$ iw dev

You'll get output similar to this

phy#0
   Interface wlan0
      ifindex 3
      wdev 0x1
      addr 12:34:56:78:9a:bc
      ssid MyWiFiNetwork
      type managed
      channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
      txpower 20.00 dBm

In this case, the interface name is wlan0. Take note of your specific interface name.

Next, check your network device's connection status by running

iw wlan0 link

If not connected, you'll see

Not connected.

Installing Network Manager

Not all Linux distributions come with nmcli pre-installed. If you need to install it, use your package manager. For Ubuntu or Debian-based systems

sudo apt-get install network-manager

The installation output will look like this

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
   libnma0 libteamdctl0 network-manager-config-connectivity-ubuntu
   network-manager-gnome
The following NEW packages will be installed:
   libnma0 libteamdctl0 network-manager network-manager-config-connectivity-ubuntu
   network-manager-gnome
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,793 kB of archives.
After this operation, 11.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Step 1: Scanning for Wi-Fi Networks

Before connecting to a Wi-Fi network, scan for available networks using

nmcli device wifi list

This command produces output like

IN-USE  SSID             MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
        MyWiFiNetwork    Infra  6     54 Mbit/s   80      ???_  WPA2      
        OtherWiFiNetwork Infra  11    54 Mbit/s   70      ??__  WPA1 WPA2 
        PublicWiFi       Infra  1     54 Mbit/s   50      ??__  --        

The output shows available Wi-Fi networks with their SSID (network name), mode, channel, data rate, signal strength, security bars, and security type.

Alternative Scanning Method

Alternatively, you can scan using the iw command

sudo iw wlan0 scan

This provides detailed technical information about each network, including encryption details and capabilities.

Step 2: Connecting to Wi-Fi Network

Once you have identified the network SSID, connect using

nmcli device wifi connect <SSID>

For a password-protected network, add the password

nmcli device wifi connect <SSID> password <PASSWORD>

Successful connection output

$ nmcli device wifi connect MyWiFiNetwork
Device 'wlan0' successfully activated with 'd0:53:49:67:8a:16'.

The output confirms the connection and shows the device's MAC address.

Step 3: Managing Wi-Fi Connections

Once connected, you can manage your connections using these commands

Disconnecting from Network

nmcli device disconnect wlan0

Successful disconnection output

Device 'wlan0' successfully disconnected.

Viewing Saved Connections

nmcli connection show

This lists all saved network connections

NAME                UUID                                  TYPE            DEVICE          
Wired connection 1  12345678-9abc-def0-1234-56789abcdef0  ethernet        enp0s25         
Wi-Fi network 1     12345678-9abc-def0-1234-56789abcdef1  wifi            wlp3s0          
Wi-Fi network 2     12345678-9abc-def0-1234-56789abcdef2  wifi            wlp3s0          

Deleting Saved Connections

nmcli connection delete <connection-name>

Example output

$ nmcli connection delete MyWifiConnection
Connection 'MyWifiConnection' (94e863e8-41dc-4e63-bb02-27cf8c1fcbe0) successfully deleted.

Additional Commands

Command Purpose
nmcli device status Show all network devices and their status
nmcli connection up <name> Activate a saved connection
nmcli connection down <name> Deactivate a connection
nmcli device wifi rescan Refresh the list of available networks

Conclusion

Using the nmcli command to connect to Wi-Fi networks from the Linux terminal is an efficient and powerful method for network management. By following these steps, you can easily scan for networks, connect to them, and manage your Wi-Fi connections entirely from the command line.

Updated on: 2026-03-17T09:01:39+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements