How to Connect to WiFi from the Terminal in Ubuntu

Windows Articles

How to permanently delete files in Windows 10

Hello, how are you? As we use the computer, it fills up with files and information. Indeed, the user is used to...

How to improve your sleep with your Android device

Every day new apps are released for our Android device, focused on different aspects of our lives. It is a world full...

Install Python 3.9 on Ubuntu 20.04 / 18.04

Hi, folks. In this post, I will show you how to install Python 3.9 on Ubuntu 20.04 / 18.08

How to Install MinGW on Windows 10

Hello! We usually work with many applications in Windows 10. However, some applications are more delicate than others. For example, native applications....

How to install Apache Tomcat on Ubuntu 20.04 / Debian 10?

Even though Python is the most popular programming language actually, there is still confidence in Java. So you probably needed to make applications with...
angeloma
angeloma
Senior Writer and partner

Ubuntu is one of the easiest Linux distributions to use thanks to its powerful and well-designed graphic interface. But what happens on servers where there isn’t one? How do I connect to a Wifi network to have the Internet from the terminal? Well, that’s the objective of this post, to learn how to connect to Wifi from the terminal on Ubuntu.

As I mentioned before, the great graphic interface of Ubuntu makes many tasks easy to do such as connecting to a network. However, in the case of servers with Ubuntu installed these do not have a graphical interface and you have to pull the terminal. But don’t worry it is much simpler than you might think.

So, let’s get started.

Learning how to connect to Wifi from terminal on Ubuntu

1.- How to get the name of the network interface of the Wifi card

One of the first things we have to do is to find out the name of the network interface of the Wifi card. In case you already know it, you can skip this step, but if you don’t, you can use the following command:

ls /sys/class/net

And in my case I get the following:

enp6s0f0 the wlp5s0

Usually, in the case of wireless cards, the name of the network interface starts with W. So in my case, it’s wlp5s0.

If you don’t see one, it’s probably not connected or you have some driver problem.

Now we can continue.

2.- The connecting to wifi process

When no graphical interface is installed on Ubuntu, all network configuration is done by Netplan. That’s why the Netplan configuration file must be modified to establish the wifi connection.

So, first create a backup of the file before editing it:

sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak

Now we can edit it with the confidence of knowing that we have a backup done.

The file is in a YAML format so you have to be careful with white spaces and editing in general.

sudo nano /etc/netplan/50-cloud-init.yaml

And, under the first configuration, add the basic information about the network you want to connect to as the SSID and the password:

wifis: wlp5s0:
    dhcp4: true
    optional: true
    access-points:
        "SSID":
         password: "password"

Then, save the changes and before applying them, make sure that the wpa_supplicant service is running to avoid problems:

sudo systemctl start wpa_supplicant
sudo systemctl status wpa_supplicant
● wpa_supplicant.service - WPA supplicant
Loaded: loaded (/lib/systemd/system/wpa_supplicant.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-10-08 12:12:28 -04; 58min ago
Main PID: 963 (wpa_supplicant)
Tasks: 1 (limit: 4414)
CGroup: /system.slice/wpa_supplicant.service
└─963 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant

With the service running correctly, it now applies the changes in Netplan.

sudo netplan generate
sudo netplan apply

And now hopefully you should be able to connect to the WiFi network.

Alternative method: using nmtui

Alternatively, it is possible to use a tool called nmtui. This tool works in some systems where Network Manager manages the networks.

This method is quite convenient to use when for some reason the Ubuntu graphical interface fails.

To do this, just type the following command in the terminal:

nmtui

And you will see the following screen where you can choose the Activate Connection option:

Using NMTUI
Using NMTUI

Then, you will see a screen where you can see the connections available in the different network interfaces. Only, choose the WiFi network you want to connect to.

Select the wifi network
Select the wifi network

Now you have to set the password in case the network is protected.

Typing the wifi password
Typing the wifi password

In the end, you will connect to the network. You can check this because a “*” will appear next to the connected network.

Connect to Wifi from terminal
Connect to Wifi from terminal

This method is quite easy and ideal for beginners.

Conclusion

It may seem that connecting to Wifi from a terminal in Ubuntu is something quite complicated but thanks to this post, you have been able to verify that it is not. So this can help you a lot in both home and production servers.

Also you can read:

How to set a static ip address on Ubuntu 20.04?

So, share this post and join our Telegram channel and our Facebook page. Also, buy us a coffee 😉

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to permanently delete files in Windows 10

Hello, how are you? As we use the computer, it fills up with files and information. Indeed, the user is used to...

How to improve your sleep with your Android device

Every day new apps are released for our Android device, focused on different aspects of our lives. It is a world full...

Install Python 3.9 on Ubuntu 20.04 / 18.04

Hi, folks. In this post, I will show you how to install Python 3.9 on Ubuntu 20.04 / 18.08

How to Install MinGW on Windows 10

Hello! We usually work with many applications in Windows 10. However, some applications are more delicate than others. For example, native applications....

How to install Apache Tomcat on Ubuntu 20.04 / Debian 10?

Even though Python is the most popular programming language actually, there is still confidence in Java. So you probably needed to make applications with...
x