How to Connect to Wi-Fi Through the Linux Terminal With nmcli



Need to connect to the internet on your Linux device, but don’t have an Ethernet port or access to graphical networking software? In this article, we’ll learn how to connect to Wi-Fi in the Linux terminal using the nmcli command.


What Is nmcli?

nmcli is the command-line interface for NetworkManager, a common Linux application for identifying and configuring internet connections. Many distributions have a graphical applet for using NetworkManager in a desktop environment, but you might not have access to a desktop if you’re on a Linux server.

Some methods of connecting with Wi-Fi through the terminal are a bit complicated, involving configuration files and knowing your PSK key.

Not so with nmcli. Assuming you have a modern router, all you need to know is your network’s SSID (the name of the network you want to connect to) and the network password, if it has one.

Step 1: Enable Your Wi-Fi Device

The Wi-Fi card on your Linux PC can’t connect to the internet unless it’s enabled. To see the status of all your network interfaces, use this command:

nmcli dev status

You should get a list of your network devices along with their type, state, and network connection info.

If you’re not sure whether your Wi-Fi device is enabled or not, you can check with this command:

nmcli radio wifi

If the output shows that the Wi-Fi is disabled, you can enable it with the following command:

nmcli radio wifi on

Step 2: Identify a Wi-Fi Access Point

If you don’t know the name of your Wi-Fi access point, otherwise known as the SSID, you can find it by scanning for nearby Wi-Fi networks.

nmcli dev wifi list

Note the name listed under SSID for the network you want to connect to. You’ll need it for the next step.

Step 3: Connect to Wi-Fi With nmcli

With Wi-Fi enabled and your SSID identified, you’re now ready to connect. You can establish a connection with the following command:

sudo nmcli dev wifi connect network-ssid

Replace network-ssid with the name of your network. If you have WEP or WPA security on your WI-Fi, you can specify the network password in the command as well.

sudo nmcli dev wifi connect network-ssid password "network-password"

Alternatively, if you don’t want to write out your password onscreen, you can use the –ask option.

sudo nmcli 

The system will now ask you to enter your network password without making it visible.

Your device should now be connected to the internet. Test it with a ping.

ping google.com

NetworkManager will save the connection and auto-connect on reboot, so you don’t have to worry about issuing the command every time you boot your Linux machine.

Managing Network Connections With nmcli

You can view all the saved connections by issuing the following command:

nmcli con show

If you’re connected to one network, but want to use a different connection, you can disconnect by switching the connection to down. You’ll need to specify the SSID, or if you have multiple connections with the same SSID, use the UUID.

nmcli con down ssid/uuid

To connect to another saved connection, simply pass the up option in the nmcli command. Make sure that you specify the SSID or UUID of the new network that you want to connect to.

nmcli con up ssid/uuid

Connecting to Wi-Fi Without a GUI on Linux

You’ve now connected to your Wi-Fi network without using a graphical interface, making you a much more versatile Linux user.

If you need to move files wirelessly, there are many Linux applications that allow for that, with or without a desktop environment.


Source link

Leave a Reply

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