Software & AppsOperating SystemLinux

How To Connect to a WPA Wifi Network Using Command Line?

Ubuntu 2

Connecting to a WPA WiFi network using the command line can be a valuable skill, especially for system administrators and those working in environments where GUI interfaces are not always available. This article will guide you through the process using two methods: wpa_supplicant and nmcli.

Quick Answer

To connect to a WPA WiFi network using the command line, you can use either the wpa_supplicant or nmcli method. With wpa_supplicant, you need to install the package, create a configuration file, and then use specific commands to connect. With nmcli, you can simply use the command nmcli c up [network name] to connect.

What is a WPA WiFi Network?

WPA stands for Wi-Fi Protected Access. It’s a security protocol designed to secure wireless (WiFi) computer networks. WPA has been in use since 2003, and it’s an upgrade from the less secure WEP (Wired Equivalent Privacy) protocol.

Connecting to WPA WiFi Network Using wpa_supplicant

wpa_supplicant is a WPA client and IEEE 802.1X supplicant that can be used to connect to a WPA network.

Step 1: Install wpasupplicant

First, ensure the wpasupplicant package is installed on your system. You can install it using the following command:

sudo apt-get install wpasupplicant

Step 2: Create Configuration File

Next, create a configuration file for wpa_supplicant. This file will contain your network details. Use the following command to create the file:

sudo nano /etc/wpa_supplicant.conf

In the file, enter your network details as follows:


Replace your_network_name and your_password with your actual network name and password.

Step 3: Connect to the Network

Finally, use the following commands to connect to the network:

sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
sudo dhclient wlan0

Here, -B makes wpa_supplicant run in the background. -i wlan0 specifies the interface to use. Replace wlan0 with your interface name. -c /etc/wpa_supplicant.conf specifies the path to the configuration file we created earlier. -D wext specifies the driver to use. Replace wext with the appropriate driver for your wireless card.

Connecting to WPA WiFi Network Using nmcli

nmcli is the command-line client for NetworkManager, a service that manages network connections on Ubuntu and other Unix-like operating systems.

Step 1: Use nmcli to Connect to the Network

To connect to a WiFi network named MYESSID using nmcli, use the following command:

nmcli c up MYESSID

Replace MYESSID with your actual network name.


In this article, we’ve covered how to connect to a WPA WiFi network using the command line. We’ve looked at two methods: using wpa_supplicant and using nmcli. Both methods require you to know your network name and password.

Remember that working with the command line can be powerful, but it also comes with risks. Always double-check your commands before running them, especially when using sudo.

For more information on wpa_supplicant, check out the official documentation. For more on nmcli and NetworkManager, see the NetworkManager documentation.

What is the difference between WPA and WEP?

WPA (Wi-Fi Protected Access) is a more secure wireless security protocol compared to WEP (Wired Equivalent Privacy). WEP is an older and less secure protocol that is susceptible to various security vulnerabilities. WPA provides stronger encryption and authentication methods, making it more difficult for unauthorized users to access the network.

How do I check if `wpasupplicant` is installed on my system?

You can check if wpasupplicant is installed on your system by running the following command in the terminal: dpkg -s wpasupplicant. If the package is installed, it will display information about the package. If it is not installed, you will see an error message.

Can I use `wpa_supplicant` to connect to networks other than WPA?

Yes, wpa_supplicant can be used to connect to other types of networks, such as WPA2, WPA3, and even open networks (networks without any security). The configuration file in wpa_supplicant can be adjusted to match the specific security settings of the network you want to connect to.

How do I find the name of my wireless interface?

You can find the name of your wireless interface by running the iwconfig command in the terminal. Look for the interface with "wireless" or "wlan" in its name. Common names include wlan0, wlp2s0, or wlan1. The exact name may vary depending on your system.

Can I connect to a hidden network using `nmcli`?

Yes, you can connect to a hidden network using nmcli. Instead of specifying the network name directly, you would need to provide the network’s SSID (Service Set Identifier) in hexadecimal format. For example, to connect to a hidden network with the SSID "MyHiddenNetwork", you would use the command nmcli c up ssid My48696464656e4e6574776f726b.

How can I view the available WiFi networks using `nmcli`?

To view the available WiFi networks using nmcli, you can run the command nmcli dev wifi list. This will display a list of nearby WiFi networks along with their SSID, signal strength, security type, and other details.

Can I connect to multiple WiFi networks simultaneously using `nmcli`?

Yes, you can connect to multiple WiFi networks simultaneously using nmcli. Each network connection will be assigned a different profile name, and you can switch between the connections using the nmcli c up command followed by the profile name.

Leave a Comment

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