3 Ways to Connect to WiFi from the Command Line on Debian

This tutorial briefly explains how to connect to Wifi from the command line on Linux Debian and Debian based distributions in 3 different ways: using nmcli, nmtui and wpa_supplicant. Additionally to nmcli, nmtui and wpa_supplicant, the commands iwconfig, iwlist and dhclient are used and briefly explained in this tutorial.

Discovering networks using Iwconfig:

Before starting we need to know the essid or name of the network we want to connect to.

This tutorial shows how to use the Iwconfig command to scan available networks. Iwconfig is similar to the command ifconfig but to manage wireless interfaces. This command allows the user to edit the frequency or channel, to change the network device mode (Ad-hoc, Managed, Master, Repeater, Monitor, Secondary), to set an ESSID, etc.

NOTE: SSID/ESSID are network or router names or identifiers.

To check if the wifi card is properly detected first execute the command iwconfig as shown in the following screenshot:

sudo iwconfig

As you can see the output shows the loopback (lo) interface,the ethernet card (enp2s0) and the wifi card wlp3s0 which we’ll use to scan available networks using the command Iwlist.

The first line shows support for 802.11 standards and reveals the device isn’t connected. The second line shows the wifi card is in managed mode, not associated with an Access Point.

The third line includes Retry Short Limit which determines the number of attempts after a failed transmission and RTS Threshold defining the number of confirmations prior to a connection, Fragment Thr shows the maximum packet size your card will send.

Last two lines show there is no authentication and Power Management is off.

The command Iwlist provides additional information on wireless devices, including those which aren’t part of our computer. In this case we will scan available networks adding the argument scan. The output will display a list of Access Points with some information such as ESSID, signal quality, channel, mode, etc.

Run the following command to print a list of available networks:

sudo iwlist wlp3s0 scan

NOTE: Replace wlp3s0 for your wireless card displayed when the command iwconfig was executed.

As you can see the output shows several networks including the LinuxHint Access Point, yet the format isn’t user friendly. If you only want to print the ESSID or names of available networks omitting the rest, run:

sudo iwlist wlp3s0 scan | grep ESSID

As you can see now the output is clear and limited to access point names (essid).

Connecting to wifi from the command line using nmcli:

NMCLI is a command line interface for the NetworkManager which can be used as an alternative to graphical managers. NMCLI allows the user to create, to edit and remove or to enable and disable connections as well as display device status.

The following syntax shows how to connect to the LinuxHint network (discovered with the previously used command Iwlist) by executing nmcli with the following arguments:

nmcli d wifi connect LinuxHint password morochita

Where d wifi specifies the wireless device, connect LinuxHint specifies the essid and password morochita the password.

NOTE: Replace LinuxHint for your router ssid and morochita for your actual password.

You can get additional information on nmcli at

Connecting to wifi from the console using nmtui:

Nmtui is an interactive curses-based alternative to nmcli and Network Manager, on the console run:


The first screen allows us to edit an existing connection, to activate a new connection and to edit our hostname. Choose the second option Activate a connection and press ENTER.

Nmtui will show both wired and wireless available networks. Select your Access Point and press ENTER.

Note: for this example the ESSID was changed from LinuxHint to LinuxH1nt to show the password request step.

The next screen will ask for the password, fill it and press ENTER to continue.

And you’ll be connected.

You can get additional information on Nmtui on it’s man page at

Connect to wifi using wpa_supplicant:

Wpa_supplicant is a supplicant which allows the negotiation in the authentication process. Contrary to nmcli and nmtui, wpa_supplicant isn’t installed by default on Debian.

To install wpa_supplicant on Debian based systems run:

sudo apt install wpasupplicant

You need to edit the file /etc/wpa_supplicant.conf adding your Access Point essid and password, you can achieve it executing the following command:

wpa_passphrase LinuxHint morochita | sudo tee /etc/wpa_supplicant.conf

NOTE: Replace LinuxHint for your essid and morochita for your actual password. You can use quotation marks for network names containing spaces.

Once wpa_supplicant.conf is edited, you can connect by executing the following command where -c specifies the configuration file and -i specifies the network interface:

sudo wpa_supplicant -c /etc/wpa_supplicant.conf -i wlp3s0


As you can see using iwconfig, now your wireless card is associated with the access point.

sudo iwconfig

To connect, run the command dhclient as shown in the following screenshot to get a dynamic IP address:

sudo dhclient wlp3s0

NOTE: Replace wlp3s0 for your wireless card.

After executing dhclient, you should be connected to the internet through the associated access point.

You can get additional information on wpa_supplicant at

I hope you found this tutorial useful to connect to wifi from the command line on Debian based systems. Keep following LinuxHint for more Linux tutorials and tips.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.