
If you have a wireless-enabled computer or laptop, you can connect to the internet. On Ubuntu you can connect to a Wi-Fi network on the terminal using the following command-line tools:
- nmtui
- nmcli
Let's see how each of these tools can be used to connect to WiFi from the terminal on Ubuntu 20.4
1) Connect to a WiFi network on the terminal using nmtui
Nmtui - Network Manager Text User Interface - is a command-line tool that is used for network configuration on Linux systems. When executed, it invokes a graphical text interface that helps users to configure network interfaces in a simple and effective manner.
It can also be used to connect to a Wireless network in these easy steps:
Step 1: Launch nmtui
To launch nmtui, simply open your terminal and run the command below:
$ nmtui
A graphical interface will be launched. Select 'Activate a connection' as shown and use the TAB key to select 'OK'.

Step 2: Connect to a wireless network
The next interface displays the network interfaces and the wireless networks that are available. As you can see, we have 2 wireless networks within range. Select the WiFi network that you want to connect to and hit ENTER. In this case, we have selected 'Milky_Way'.

Provide the password for the wireless network in the pop-up dialogue box that appears and, once again, use the TAB key to select the 'OK' option.

Once you have successfully connected to your wireless network, select the 'Back' option to get back to the home screen of the nmtui interface, and finally select 'Quit'.

To test your internet connectivity, you can ping Google's DNS on the terminal as shown:

2) Connect to a WiFi network on the terminal using nmcli
The nmcli command-line tool is yet another utility you can use to connect to a wireless or WiFi network. Follow the steps below to connect to a wireless network on the terminal.
Step 1: Find out the name of your WiFi adapter and wireless network
Before anything else, use the iwconfig
command to display the wireless interfaces on your system and check their status
$ iwconfig

From the output above, we can see that we have a wireless interface labeled wlxc4e9840c3fce
. This may be something else for your case. Also, from the output, we can see that we are not connected to any wireless network.
To list wireless interfaces only run the command:
$ iw dev

You can also check whether the interface is connected to any wireless device using the command:
$ iw interface_name link
In this case, the command will be:
$ iw wlxc4e9840c3fce link

The output confirms that we are not connected to any wireless network. Let's now proceed to the next step and connect to a WiFi network.
Step 2: Connect to WiFi on the terminal
Before connecting to a WiFi network, it's prudent to perform a scan on the terminal to search the available Wireless networks. To achieve this, run the command:
$ sudo iwlist wlxc4e9840c3fce scan | grep -i ESSID

The output indicates that we have 2 wireless networks at our disposal which we can connect to. We are going to connect to the 'Milky_Way' network using the nmcli command :
$ nmcli dev wifi connect [essid_name] password [insert your password]

After running the command, you should get the output that confirms that you have successfully connected to the WiFi network. Thereafter, confirm that your interface is connected using the iwconfig
command as shown above.
Also, you can verify this using :
$ sudo iw wlxc4e9840c3fce link

Conclusion
Usually, most users would rather use the graphical means to select and connect to their preferred wireless network. However, for terminal geeks, connecting to a WiFi network is also a viable option and only takes a few simple steps.
For earlier versions on Ubuntu such as Ubuntu 16.04 and Ubuntu 17.10, you can use the wpasupplicant tool to connect to a WiFi network on the terminal. We hope that you can now connect to your preferred wireless network with ease. Your feedback is most welcome.
Excelent tutorial!
I'm a Linux user since 1993 and never heard about these commands!
Super useful!
Thanks a lot!
? fatal: repository 'https://github.com/lwfinger/rtlwifi_new.git/' not found
How do I get this to stick? After I use nmtui it works but only up until I restart.
Thanks again, very useful tools!