Would you like to connect to a Wi-Fi network using the Linux command line? Here's what you need to know about the nmcli command.
Need to connect to the Internet on your Linux device but don't have an Ethernet port or access to graphical network software? This article will show you how to use the nmcli command line tool to connect to Wi-Fi in the Linux terminal.
What is nmcli
Nmcli is the command line interface for NetworkManager, a popular Linux application used to identify and configure Internet connections. Many distributions have a graphical applet for using NetworkManager in a desktop environment. However, if you are on a Linux server, you may not have access to a desktop.
Some methods of connecting to Wi-Fi through the terminal are a little tricky. This includes configuration files and knowing your PSK key.
Not so with nmcli. Assuming you have a modern router, all you need to know is that of your network SSID (the name of the network you want to connect to) and the network password, if any.
Step 1: Activate your Wi-Fi device
The Wi-Fi card on your Linux PC can only connect to the internet if it is enabled. Use the following command to view the status of all network interfaces:
nmcli dev status
You should be given a list of your network devices with information about their type, status, and network connection.
If you are not sure whether your Wi-Fi device is enabled or not, you can check it with the following command:
nmcli radio wifi
If the output shows that this is Wi-Fi deactivated, 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, also known as its SSID, you can find it by searching for nearby Wi-Fi networks.
nmcli dev wifi list
Note the name listed below SSID for the network you want to connect to. You will need it for the next step.
Step 3: Connect to Wi-Fi
With Wi-Fi enabled and your SSID identified, you are now ready to connect. You can connect with the following command:
sudo nmcli dev wifi connect network-ssid
Replace Network SSID with the name of your network. If your WI-Fi has WEP or WPA security, you can also provide the network password in the command.
sudo nmcli dev wifi connect network-ssid password "network password"
Alternatively, if you don't want to write your password out on the screen, you can use that –Ask Possibility.
sudo nmcli –ask dev wifi connect network-ssid
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.
NetworkManager saves the connection and automatically connects when it restarts so you don't have to worry about what the command is issued every time you start your Linux computer.
Manage network connections with nmcli
You can view all saved connections by entering the following command:
nmcli con show
If you're connected to one network but want to use a different connection, you can disconnect by changing the connection Low. You have to enter the SSID. If you have multiple connections with the same SSID, use the UUID.
nmcli con down ssid / uuid
To connect to another saved connection, just pass the above Option in the nmcli command. Make sure to provide the SSID or UUID of the new network that you want to connect to.
nmcli con up ssid / uuid
Connect to Wi-Fi without a GUI
You have 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 plenty of Linux applications out there to make it happen, with or without a desktop environment.
The 7 best wireless file transfer apps on Linux
Do you need to transfer your files over Wi-Fi on Linux? Here are several different methods you can use.
About the author
(33 articles published)
Jordan is a tutor and journalist who is passionate about making Linux accessible and stress-free for everyone. He has a BA in English and a thing for hot tea. During the warm season he enjoys cycling on the Ozark hills where he lives.
By Jordan Gloor
Subscribe to our newsletter
Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!
One more step …!
Please confirm your email address in the email we just sent you.