Connecting to a Wi-Fi network via the command line is a useful feature on Ubuntu Server or other Ubuntu installations that do not have a desktop environment installed. This allows headless systems to utilize Wi-Fi connectivity instead of being limited to wired connections. GUI systems can, of course, use this trick as well, but it would usually be easier to click through the built-in method provided by the desktop environment.
In this tutorial, you will learn how to connect to Wi-Fi using only the command line on Ubuntu Linux. This function is facilitated through Netplan, which is Canonical’s own frontend for the Linux network managers, and is configured through YAML files. Follow along with us below to see how it works!
In this tutorial you will learn:
- How to identify the name of your wireless network interface
- How to configure Netplan to connect to wireless network (SSID)

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Ubuntu Linux LTS versions 20.04, 22.04, 24.04 |
Software | Netplan (installed by default) |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Ubuntu Server: Connecting to Wi-Fi via Command Line
Follow along with the step by step instructions below to configure the Netplan YAML file, and then connect your Ubuntu system to a Wi-Fi network using the command line terminal:
- The first thing we need to do is identify the name of our system’s network interface. We can do this by running
ip a
or even more simply by checking the following directory:$ ls /sys/class/net ens33 lo wlo1 Your Wi-Fi interface will likely start with a “w” – in our case, the interface name iswlo1
. Other common names includewlp3s0
orwlan0
, but your system’s could be totally different. - The next thing to do is edit the Netplan configuraton file. Use root permissions to open the file below with your preferred text editor. In this example, we will use nano:$ sudo nano /etc/netplan/50-cloud-init.yaml NOTE
If the 50-cloud-init.yaml file does not already exist, you can alternatively use the 01-network-manager-all.yaml file. If neither exist, you will need to create the file from scratch and paste the extended example below as a template. - Inside of this file, copy and paste the following configuration stanza, while replacing the
SSID-NAME-HERE
andPASSWORD-HERE
text with your SSID network name and password:wifis: wlan0: optional: true access-points: "SSID-NAME-HERE": password: "PASSWORD-HERE" dhcp4: true
Copy
USE PRECISE FORMATTING
Take a close look at the formatting used above. Each line has a certain indentation, which might seem arbitrary, but is essential for proper functioning. This is why it is recommended to copy and paste the code above, so that you can retain the correct formatting when editing the configuration file.
The code above can be pasted after theethernets
stanza, but still within thenetwork
heading. The complete file should look something like this:# This file is generated from information provided by the datasource. Changes # to it will not persist across an instance reboot. To disable cloud-init's # network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: eth0: dhcp4: true optional: true version: 2 wifis: wlp3s0: optional: true access-points: "SSID-NAME-HERE": password: "PASSWORD-HERE" dhcp4: true
CopyObserve the formatting of the YAML file in this image - After saving your changes to the file and exiting, apply the new Netplan configuration:$ sudo netplan apply At this point, your Ubuntu system should connect to the Wi-Fi network that you had configured.
- If all went well, you will be able to see your wireless adapter connected to the wireless network by executing the
ip
command:$ ip a
Troubleshooting Netplan Errors
When attempting to apply the new Netplan configuration, you may encounter an error message similar to the one below:
/etc/netplan/50-cloud-init.yaml:20:11: Invalid YAML: inconsistent indentation: access-points: ^
This error means that something is wrong with the indentation in the YAML formatting. Return to the example above and try copying and pasting the example into the configuration file, before substituting your own SSID and Wi-Fi password.
If you encounter further issues, you can try using the --debug
option to get more information about what is going wrong:
$ sudo netplan --debug apply
Closing Thoughts
In this tutorial, we saw how to connect to a Wi-Fi network from the command line on an Ubuntu Linux system. By editing the Netplan configuration file with the proper YAML formatting, we can easily connect to secure Wi-Fi networks, and the system will remember these settings and connect automatically whenever reboots occur. This process is handy for all headless Ubuntu systems or anyone who prefers using the command line to configure system settings.