How to connect to WiFi using nmcli

Below are commands that you can use to connect and check the status of your WiFi connection using nmcli.

I usually use this when connecting my Rock Pi running Ubuntu to the WiFi Network. But commands below will also work as long as you have the nmcli in your Linux System.


Turn On WiFi

# Turn on WiFi
nmcli r wifi on

Scan WiFi Networks

# Scan WiFi Networks
nmcli dev wifi

Connect to WiFi Network

# Connect to a WiFi Network
nmcli dev wifi connect "wifi_ssid" password "wifi_password"

# Output - Successful connection
Device 'wlan0' successfully activated with 'da903216-197a-4f06-8f27-d97f3e884e38'.

Connect to a hidden WiFi Network

# Connect to a hidden WiFi Network
# Needs sudo privileges
sudo nmcli dev wifi connect "wifi_ssid" password "wifi_password" hidden yes

Check which WiFi network the device is connected

# Command to check which wifi network connected
nmcli dev status

# Output
wlan0          wifi      connected    wifi_ssid
eth0           ethernet  unavailable  --
lo             loopback  unmanaged    --
p2p-dev-wlan0  wifi-p2p  unmanaged    --

Delete the connection if you no longer need it.

# Delete the connection
# Needs sudo privileges
sudo nmcli c delete wifi_ssid

# Output
Connection 'wifi_ssid' (efaa0bac-a317-407d-9fc0-92a262ca7b60) successfully deleted.

# Output without sudo
Error: Connection deletion failed: Insufficient privileges
Error: not all connections deleted.

Check all known connection

# Check all known connections
nmcli c

# Output
NAME                UUID                                  TYPE      DEVICE
wifi_ssid           da903116-197a-4f08-8e27-d97f3e884e44  wifi      wlan0
wifi_ssid_2         efaa0bac-a317-407d-9fc0-92a262ca7c70  wifi      --
wifi_ssid_3         c4b8c226-9a02-4253-977c-21c5f0e0533c  wifi      --
Wired connection 1  83b3e3e1-5060-3b75-b922-af239f1ec64d  ethernet  --

Check if WiFi is on or off

# Check status of WiFi
nmcli r wifi

# Output
enabled - if on
disabled - if off

Turn off WiFi

# Turn off WiFi
nmcli r wifi off

We hope this helps you connect your devices to the WiFi network using nmcli.

If you have any difficulties or have questions do let us know in the comment section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.