3 Minute Guide: Set Up WiFi on Ubuntu Server or Linux Using the Command Line

By utilizing nmcli, this guide will show you how to set up WiFi on Ubuntu Server or Linux - this image shows a command line output showing that WiFi has been set up

The process to set up WiFi on Ubuntu server or Linux in general can be a little daunting, if you’re not familiar with it. Unlike Windows or MacOS, where you can use your mouse and graphical interface, with Ubuntu Server, you will need to use the command line interface. But, don’t let this deter you as this process is very simple using a nifty tool called nmcli!

This is a very straightforward, and easy to follow guide that will have you set up WiFi on Ubuntu Server in as little as 3 minutes. This guide has you covered from start to finish, and even set up WiFi on Ubuntu Server using a hidden WiFi network too! By utilizing nmcli, a great Linux utility, we will be able to set up, configure and save a WiFi connection using the command line. Let’s jump right in to it!

Set Up WiFi on Ubuntu Server or Linux: First Step

Either use a keyboard on the device itself and use the terminal there. Or establish an SSH connection to your device running Ubuntu Server by plugging in an Ethernet cable from your router to the device and logging into the device.

Now, install Network Manager using apt. Type the following command into your terminal and type ‘y’ when asked to initiate the installation:

sudo apt install network-manager

If you receive a message saying network-manager cannot be found such as:

E: Unable to locate package network-manager

You may need to run the following command and then re-run the previous command:

sudo apt update

Once network-manager is installed, we will list out all the adapters currently available to use. Type the following command into your terminal:

nmcli d

After running that command, you should get an output that looks something similar to:

$ nmcli d
DEVICE                   TYPE      STATE         CONNECTION
wlx74da38661d72          wifi      disconnected     --
eth0                     ethernet  unmanaged        --
lo                       loopback  unmanaged        --
p2p-dev-wlx74da38661d72  wifi-p2p  unmanaged        --

Look for the DEVICE with a TYPE of ‘wifi’ (not ‘wifi-p2p). On the off chance you don’t have any devices with a type of wifi, your USB WiFi Dongle is probably not supported for linux and you should get/try a different dongle. If a device does appear, you are good to go. Make sure the WiFi radio is turned on by running:

nmcli r wifi on

If you are broadcasting your network (or are unsure what this means), use the Regular WiFi Network steps. If you are not broadcasting your network, skip to the Hidden WiFi Network steps.

Regular WiFi Network

Next step is to list out the available WiFi networks. Run this:

nmcli d wifi list
$ nmcli d wifi list
*  SSID                MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
   my_wifi_name_here   Infra  5     54 Mbit/s  89      ▂▄▆█  WPA2

Now connect to your WiFi network. Use the following command. In this example output above, the <ssid> would be my_wifi_name_here.

nmcli d wifi connect <ssid> password <password>

Hidden WiFi Network

For connecting to a hidden network, you will want to make note of the Device Name. Giving the above output of all of the adapters available, the device name would be wlx74da38661d72. With that device name ready, run:

nmcli c add type wifi con-name <a unique name> ifname <device name> ssid <ssid>

Using the example information, my command would look like:
nmcli c add type wifi con-name mywifi ifname wlx74da38661d72 ssid my_wifi_name_here

Next, we want to set up the password.

nmcli c modify <name> wifi-sec.key-mgmt wpa-psk wifi-sec.psk <password>

Using the example information, my command would look like:
nmcli c modify mywifi wifi-sec.key-mgmt wpa-psk wifi-sec.psk abcde12345

All that is left is to start up your connection with:

nmcli c up <name>

Using the example information, my command would look like:
nmcli c up mywifi

WiFi Network Wrap Up

Now that you have set up WiFi on Linux, you can additionally set a static IP address too. I have written a super simple and fast guide found at Set Static IP Address on Linux.

For more information on both hidden and regular WiFi network setup in Ubuntu Server using the CLI, read the official documentation page for Configure WiFi Connections.

Obtain your new IP address:

hostname -I
$ hostname -I

I had a really tough time setting up a hidden network using the command line. After finally figuring out how to do it, I wanted to share and give examples to make things clear. I hope this helped solve your CLI WiFi issues!

You May Also Enjoy

Setup Windows SMB Share on Kodi

Kodi splash screen to represent setting up Windows SMB shares on Kodi

A guide for setting up a Windows SMB share on Kodi. All steps including anonymous/no user login.

Non HP Chip Detected – Quick Fix

A photo showing the Non HP Chip Detected error message on my HP OfficeJet Pro 6978

A quick and simple solution for apply the Non HP Chip Detected fix to your HP Printer!

Quick and Easy Set Static IP Address on Linux Guide

A command line terminal showing some of the Linux set static IP address commands on it.

A super simple and fast guide for setting a static IP address on Linux using the nmcli utility!

Posted in


One response to “3 Minute Guide: Set Up WiFi on Ubuntu Server or Linux Using the Command Line”

  1. Dave Ens Avatar
    Dave Ens

    Super helpful. I was struggling with /etc/netplan/ on a server setup, and didn’t know there was a command line version of nmcli that was so functional. There’s been so many times I’ve tried using nm-connection-editor over VNC and struggled with root DISPLAY forwarding, etc. This is so much nicer!

Leave a Reply

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