How to Connect to Wi-Fi via the Linux Console: A Complete Guide

Working in the Linux operating system often requires interaction with the command line, especially when the graphical interface is unavailable or overloaded. Connecting to a wireless network — one of the basic tasks faced by every administrator or advanced user. Unlike the traditional mouse click, the console method provides complete control over the process and allows for troubleshooting at a low level.

There are several basic tools for managing network connections in LinuxThe most popular are utilities nmcli (NetworkManager), wpa_supplicant And iwdThe specific tool you choose depends on your distribution and installed packages, but the principles of working with Wi-Fi remain similar: scanning the airwaves, authenticating, and obtaining an IP address.

In this article, we'll take a detailed look at how to connect to Wi-Fi via a terminal using modern methods. You'll learn how to create connection profiles, save passwords, and troubleshoot common errors. This knowledge will come in handy when setting up servers, performing remote administration, or restoring the system after a graphical shell crash.

Checking the status of the wireless adapter

Before you try to connect to the network, you need to make sure that your wireless adapter The device is correctly detected by the system and the drivers are working properly. Users often skip this step, attempting to establish a connection on a disabled or blocked interface. First, check the device's presence in the system.

To do this, use the command ip link or more specialized iw devIn the output, you should see the name of your interface, which usually looks like wlan0, wlp2s0 or similar. If the list is empty or the interface is marked as DOWN, you will need to enable it or check the drivers.

⚠️ Attention: If the team iw dev If the error or empty list returns, you may not have the drivers for the Wi-Fi module installed. In this case, you'll need a wired connection or a USB modem to install the missing packages.

Make sure the interface is activated. If the device status is DOWN, raise it with the command ip link set dev interface_name upIt's also worth checking whether the adapter is blocked by software or hardware (for example, by the Fn key on a laptop) using a utility rfkill list.

Using NetworkManager (nmcli) to connect

The most common and convenient tool in modern distributions such as Ubuntu, Fedora And Debian, is NetworkManagerIts console utility nmcli Allows you to manage your network without having to write complex configuration files manually. It's the ideal choice for both beginners and professionals alike.

First, scan for available networks to find the exact name (SSID) of the access point. Run the scan command, specifying your interface:

nmcli dev wifi list

In the list you will see a column SSID, signal, and security type. Find the desired network and remember its name. If the network is hidden, it may appear as <hidden>, and then you'll need to know the SSID in advance. After that, you can initiate the connection.

☑️ Preparing to connect via nmcli

Completed: 0 / 4

To connect, use the command and substitute your details. Note that if the SSID contains spaces, it's best to enclose it in quotation marks:

nmcli dev wifi connect "Network_Name" password "Your_Password"

The system will automatically create a connection profile and attempt to obtain an IP address via DHCP. If successful, you'll see a message confirming device activation. This is the fastest way. connect to Wi-Fi without unnecessary movements.

📊 Which Linux distribution do you use most often?
Ubuntu
Debian
Arch Linux
CentOS/Fedora
Another

Setting up a connection via wpa_supplicant

On more minimalistic systems or on servers where it is not installed NetworkManager, the main instrument remains wpa_supplicantThis daemon is responsible for negotiating with the access point and encrypting traffic. Working with it requires creating a configuration file, which provides flexibility but is more difficult to implement.

The first step is to generate a hashed password for your network. This is done for security reasons, so you don't have to store the password in plaintext in the configuration. Use the utility wpa_passphrase, specifying the SSID and password:

wpa_passphrase "My_Setup" "Complex_Password123"

The command output contains a block network, which needs to be saved to the configuration file. Typically this is /etc/wpa_supplicant/wpa_supplicant.confYou can add this block to the end of the file using a text editor. nano or vim.

⚠️ Warning: The wpa_supplicant.conf configuration file may contain cleartext passwords if you don't use hashing. Restrict file permissions with chmod 600 to prevent other system users from reading it.

After preparing the file, start the daemon by specifying the interface and configuration path. The process often requires running in the background:

wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Next, you need to obtain an IP address. A DHCP client is usually used for this, for example, dhcpcd or dhclientWithout this step, the network connection will be established, but the Internet will not work.

What to do if wpa_supplicant does not start?

If the daemon doesn't start, check whether the wpa_supplicant process is already running for this interface. Also, make sure NetworkManager isn't conflicting with it by attempting to manage the same device. In such cases, it's best to disable one of the services.

Comparison of Wi-Fi management tools

The choice between nmcli, wpa_supplicant And iwd depends on your goals. NetworkManager Convenient for desktops and laptops where networks change frequently. wpa_supplicant - this is a classic for servers, and iwd (iNet wireless daemon) is a modern replacement for systemd from the developers, distinguished by its speed.

The table below compares the key features of these utilities so you can choose the right tool for your task.

Tool Complexity Dependencies Best use
nmcli Low NetworkManager Desktops, laptops
wpa_supplicant Average No (basic) Servers, old systems
iwd Average systemd (preferred) Modern distributions
iwconfig High wireless-tools Legacy systems

It is worth noting that iwctl (interactive shell for iwd) is becoming the standard in distributions such as Arch LinuxIt combines ease of use with the power of a new engine. However, for most users nmcli remains the most universal solution.

Solving common connection problems

Even if you enter commands correctly, errors may occur. Often, the problem lies in an incorrect password or encryption type. If the system reports an authentication error, double-check your keyboard layout and capitalization. Case sensitive jokes are bad.

Another common issue is an IP address conflict or an unresponsive DHCP server. In this case, you can try assigning a static IP address manually if you know your network settings. It's also worth checking whether a firewall is blocking the connection.

Sometimes the wireless card driver may freeze. In this case, restarting the kernel module helps. Use the following commands: modprobe -r to remove the module and modprobe to reload it. This often solves the problem of a "dead" interface.

Automation and profile saving

When using NetworkManager connection profiles are saved automatically in the directory /etc/NetworkManager/system-connections/This allows the system to automatically connect to known networks upon boot. You can edit these files, but it's best to do so using commands. nmcli connection modify.

For wpa_supplicant Automation is achieved by adding daemon startup to initialization scripts (rc.local or systemd service). It's important to configure the service so that it starts after the drivers are loaded, but before attempting to mount network resources.

⚠️ Note: Command line interfaces and configuration file locations may vary across distributions. Always consult the documentation for your OS version if the default paths don't work.

Setting up auto-connection is critical for servers. Make sure the connection profile has the parameter set autoconnect in meaning yes. IN nmcli this is done with a flag connection.autoconnect yes when creating or editing a profile.

How to delete a saved network profile in Linux?

To delete a profile in NetworkManager, use the command: nmcli connection delete "Profile_Name"This will delete the saved settings and password for this network, and the system will no longer try to connect to it automatically.

Where are Wi-Fi passwords stored in Linux?

Passwords are typically stored in NetworkManager configuration files at /etc/NetworkManager/system-connections/. These files are protected by root access. In some cases, passwords may be encrypted using the user session keyring.

Why are 5 GHz networks not visible when scanning?

This may be related to your region settings (country code). Make sure the wireless-regdb configuration is set to the correct country code for your country. Also, some older adapters don't support the 5 GHz band.