Connecting to Wi-Fi manually every time you start Linux is a tedious chore, especially if you frequently move between networks or use your laptop in different locations. Fortunately, all modern distributions support this. automatic connection to saved networks, but setting up this functionality depends on the network manager used. In some cases, the system connects automatically, while in others, manual editing of configuration files is required.
In this article, we will look at three main methods for setting up auto-connection: through a graphical interface NetworkManager (the easiest way for beginners), using the utility netctl (popular in Arch Linux and derivatives) and through wpa_supplicant (a universal method for server systems without a GUI). You'll also learn how to troubleshoot common issues, such as when the network is saved but the connection fails, or when Linux ignores priority networks.
Be warned in advance: if you use non-standard Wi-Fi drivers (for example, for adapters Broadcom or Realtek (If you have proprietary firmware, make sure it's installed correctly first. Otherwise, even if auto-connection is configured correctly, it won't work.)
1. Auto-connection via NetworkManager (GUI and CLI)
NetworkManager — the most common network manager in Linux, used by default in Ubuntu, Fedora, Debian and many other distributions. It supports both a graphical interface and terminal control. Let's look at both options.
If you have a graphical shell installed (GNOME, KDE Plasma, XFCE etc.), the fastest way:
- Click on the network icon in the system tray (usually in the upper right corner).
- Select the desired Wi-Fi network from the list and connect to it manually (enter the password if required).
- After a successful connection, open the network settings (usually through the same icon → "Network Settings" or "Edit Connections").
- Find your network in the list, open its properties and check the box next to
Connect automatically(orAutomatically connect to this network(in the English version).
For terminal use the command nmtui (text interface) or nmcli (command line). Example for nmcli:
# View the list of saved networksnmcli connection show
Enable auto-connection for the network named "MyWiFi"
nmcli connection modify"MyWiFi" connection.autoconnect yes
Restart NetworkManager to apply changes.
sudo systemctl restart NetworkManager
If the network doesn't connect automatically despite the settings, check the connection priority. NetworkManager sorts networks by priority. connection.autoconnect-priorityTo set the priority (the higher the number, the higher the priority):
nmcli connection modify"MyWiFi" connection.autoconnect-priority 10
⚠️ Attention: In some distributions (for example, Ubuntu Server without GUI) NetworkManager may be disabled by default. Check its status with the commandsystemctl status NetworkManagerand enable if necessary:sudo systemctl enable --now NetworkManager.
2. Configuration via netctl (Arch Linux and derivatives)
netctl - This is the default network manager in Arch Linux and some other distributions. It uses configuration profiles that are stored in /etc/netctl/To set up auto-connection:
First, create a profile for your network (if you don't have one yet). The easiest way is to generate one automatically:
sudo wifi-menu -o
This command will scan for available networks, prompt you to select one, and enter the password. The profile will then be saved to /etc/netctl/ with a species name wlan0-YourNetwork.
Now enable the profile to start automatically at system startup:
sudo netctl enable YourNetwork
To check if the profile is activated, use:
sudo netctl list
sudo netctl status YourNetwork
☑️ Checking netctl settings
If you have multiple networks and want to set priority, edit the profile (eg. sudo nano /etc/netctl/YourNetwork) and add the line:
Priority=10
The higher the value, the higher the priority. Save the file and restart the service:
sudo systemctl restart netctl
⚠️ Attention: netctl conflicts with NetworkManagerIf both managers are active, the network connection may become unstable. Disable one of them, for example: sudo systemctl disable --now NetworkManager.
3. Manual control via wpa_supplicant (universal method)
wpa_supplicant is a low-level Wi-Fi utility used in many distributions, including server versions without a graphical interface. It requires manual configuration but provides maximum control over connections.
The main configuration file is /etc/wpa_supplicant/wpa_supplicant.confOpen it with superuser rights:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add a block for your network. Example for a network with WPA2-PSK (the most common type of encryption):
network={ssid="YourNetworkName"
psk="your_password"
priority=5
}
Parameters that can be configured:
- 🔄
priority— network priority (the higher the priority, the earlier the connection attempt will be made). - 🔒
key_mgmt— a key management method (e.g.WPA-PSKfor home routers). - 📡
scan_ssid- if the network is hidden (does not broadcast SSID), addscan_ssid=1. - 🔄
disabled=1- temporarily disable the network without deleting it.
After saving the file, restart the service:
sudo systemctl restart wpa_supplicant
To wpa_supplicant connected automatically on boot, make sure the service is enabled:
sudo systemctl enable wpa_supplicant
4. Network Prioritization: Why Linux Connects to the Wrong Network
If there are multiple saved networks in range, Linux may connect to a different network than you expect. This happens because prioritization algorithm, which depends on the network manager. Let's look at how this works in different cases.
IN NetworkManager priority is determined by the parameter connection.autoconnect-priority (as mentioned earlier). If not specified, networks are sorted by:
- Reliability of the last connection (if the network frequently drops out, its priority is lowered).
- Signal strength (but this is not always a reliable criterion).
- Time of last successful connection.
IN netctl And wpa_supplicant priority is set explicitly through a parameter priority in the configuration file. If it is not specified, networks are connected in the order they are declared in the file (top to bottom).
To check the current connection order in NetworkManager, use:
nmcli -f NAME,AUTOCONNECT,AUTOCONNECT-PRIORITY connection show
| Network Manager | Priority parameter | Command for checking | Command to change |
|---|---|---|---|
| NetworkManager | connection.autoconnect-priority |
nmcli connection show |
nmcli connection modify"Name" connection.autoconnect-priority 10 |
| netctl | Priority= in profile |
netctl list |
Edit /etc/netctl/NetworkName |
| wpa_supplicant | priority= V wpa_supplicant.conf |
wpa_cli list_networks |
Edit /etc/wpa_supplicant/wpa_supplicant.conf |
If Linux keeps connecting to the "wrong" network, try:
- 🔍 Remove unnecessary networks from saved (
nmcli connection delete"Name"or delete the profile in/etc/netctl/). - 📶 Temporarily disable the unwanted network on your router (for example, the guest network, if it is interfering).
- 🔄 Restart the network service (
sudo systemctl restart NetworkManageror similar for your manager).
5. Troubleshooting: Network saved but won't connect
A network connection, but auto-connection, isn't working, is a common occurrence. There could be various reasons, from incorrect security settings to conflicts with other services. Here's a diagnostic checklist:
- Check if the network service is active. For example, for NetworkManager:
sudo systemctl status NetworkManagerIf the service is not running, enable it:
sudo systemctl enable --now NetworkManager - Make sure your Wi-Fi adapter is not blocked. Check the status of the radio module:
rfkill listIf the adapter is blocked (for example, by a hardware switch on a laptop), unlock it:
sudo rfkill unblock wifi - Check the error log. For NetworkManager:
journalctl -u NetworkManager --no-pager | grep -i errorFor wpa_supplicant:
sudo wpa_cli log_level debugtail -f /var/log/syslog | grep wpa
Common mistakes and their solutions:
- 🔌 Authentication error: Incorrect password or encryption type. Delete the network and save it again. To wpa_supplicant check the parameter
key_mgmt(must match the router settings, for example,WPA-PSKForWPA2). - 📵 Network not found: It's possible that your router is hiding your SSID. wpa_supplicant add
scan_ssid=1in the network block. In NetworkManager When creating a connection, check the box "Connect even if the network is not broadcast." - ⚡ IP address conflict: If there's already a device on the network with the same IP address, Linux may fail to connect. Try manually setting a static IP in the network settings or rebooting the router.
How do I reset my network settings to factory defaults?
If the problems persist, sometimes it's easier to reset all network settings. NetworkManager delete all saved connections:
nmcli connection delete $(nmcli -t -f NAME connection show)
For wpa_supplicant delete the configuration file:
sudo rm /etc/wpa_supplicant/wpa_supplicant.conf
After this, reboot the system and configure the networks again.
6. Auto-connect to hidden networks (not broadcasting SSID)
Hidden networks (where the SSID isn't broadcast) require additional configuration. In most cases, manually entering the network name is sufficient, but sometimes you'll need to configure scanning.
IN NetworkManager:
- Open network settings via
nmtuior graphical interface. - Create a new connection → select
Wi-Fi. - In the field
SSIDEnter the name of the hidden network. - Check the box
Connect even if the network is not broadcast(orConnect even if the network is not broadcasting). - Save and enable auto-connection.
IN wpa_supplicant add the following line to the network config:
scan_ssid=1
Example of a complete block:
network={ssid="HiddenNetwork"
scan_ssid=1
psk="password"
priority=10
}
For netctl edit network profile (/etc/netctl/ProfileName) and add:
Hidden=yes
⚠️ Attention: Hidden networks do not provide additional security - their SSIDs are easy to identify using traffic analyzers (for example, Wireshark or airodump-ng). Use them only if required by network policy (for example, in some corporate environments).
7. Automatic connection at system startup (systemd)
If you use systemd (which is the case with most modern distributions), you can set up automatic connection via services. This is useful if standard methods don't work or you need to perform additional steps before connecting (for example, setting up a VPN).
Create a new service to connect to Wi-Fi. Example for wpa_supplicant:
sudo nano /etc/systemd/system/wifi-autoconnect.service
Add the following content (replace wlan0 to your interface):
[Unit]Description=Automatically connect to Wi-Fi on boot
After=network.target
[Service]
Type=oneshot
ExecStart=/sbin/wpa_cli -i wlan0 reconfigure
[Install]
WantedBy=multi-user.target
Activate the service:
sudo systemctl enable wifi-autoconnect.service
For NetworkManager You can use a similar approach, but it's easier to use the built-in autoconnect feature. However, if you need to, for example, wait for the network to come online first, create a service with a script:
[Unit]Description=Wait for Wi-Fi and connect
After=NetworkManager.service
Requires=NetworkManager.service
[Service]
Type=simple
ExecStart=/bin/bash -c'while! nmcli device wifi list | grep -q"YourNetwork"; do sleep 5; done; nmcli connection up"YourNetwork"'
[Install]
WantedBy=multi-user.target
This script will wait for a network to appear in the list of available networks and connect to it. Useful for laptops that wake from sleep mode in different locations.
8. Security: How to protect saved Wi-Fi passwords
Wi-Fi passwords in Linux are stored in clear or encrypted form depending on the network manager. NetworkManager They are accessible by default to any user with permissions sudo, which can be unsafe on private machines. Let's look at how to protect this data.
IN NetworkManager passwords are stored in /etc/NetworkManager/system-connections/Each network is a separate file with the extension .nmconnectionTo view your password:
sudo grep psk /etc/NetworkManager/system-connections/*
To restrict access:
- Change folder permissions:
sudo chmod 700 /etc/NetworkManager/system-connections/ - Make sure the configuration files are owned
root:sudo chown root:root /etc/NetworkManager/system-connections/*
IN wpa_supplicant passwords are stored in /etc/wpa_supplicant/wpa_supplicant.confBy default, the file is only accessible root, but if you changed the rights, return them:
sudo chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
For additional security, you can encrypt your passwords using wpa_passphrase, but this does not protect against users with rights sudoFull encryption requires the use of LUKS or similar tools for full-disk encryption.
For maximum security in corporate networks:
- 🔐 Use authentication by
802.1X(EAP) instead of passwords. - 🛡️ Set up MAC filtering on the router (although this is not a panacea).
- 🔄 Change Wi-Fi passwords regularly and use complex combinations.
⚠️ Attention: If you connect to public Wi-Fi (for example, in cafes or airports), never save these networks With automatic connection. Attackers can deploy a router with the same SSID and intercept your traffic. Use a VPN or connect manually only when necessary.
FAQ: Frequently Asked Questions about Auto-Connecting Wi-Fi in Linux
My Linux box won't connect to Wi-Fi automatically, even though the network is saved. What's the problem?
There may be several reasons:
- Network priority too low (check
connection.autoconnect-priorityV NetworkManager orpriorityV wpa_supplicant). - Conflict with other network managers (e.g., working at the same time) NetworkManager And netctl).
- Wi-Fi adapter is blocked (
rfkill list). - Incorrect encryption type (for example, the router uses
WPA3, and it is specified in the configWPA2).
Start by checking the logs: journalctl -u NetworkManager or dmesg | grep wifi.
How can I make Linux connect to 5 GHz instead of 2.4 GHz?
Most modern routers broadcast two networks with the same SSID but different frequencies. To prioritize the 5 GHz band:
- IN NetworkManager create two separate profiles for one network (eg.
MyWiFi-2.4AndMyWiFi-5) and set a higher priority for 5 GHz. - IN wpa_supplicant add parameter
frequency=5000into the network block (but this will only work if the network is broadcast on a fixed channel). - On some routers you can disable it
Band Steering(automatic switching between frequencies) and set different SSIDs for 2.4 and 5 GHz.
Is it possible to set up automatic connection to a VPN after connecting to Wi-Fi?
Yes, it is done through systemd. Example:
- Create a service to connect to the VPN (
/etc/systemd/system/vpn-autoconnect.service): - Activate the service:
[Unit]Description=Auto-connect to VPN after Wi-Fi
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/sudo /usr/bin/openvpn /etc/openvpn/client.conf
[Install]
WantedBy=multi-user.target
sudo systemctl enable vpn-autoconnect.service
For NetworkManager You can use the built-in VPN connection feature with the option connection.autoconnect-vpn.
How to delete all saved networks in Linux?
The method depends on the network manager:
- NetworkManager:
nmcli connection delete $(nmcli -t -f NAME connection show) - wpa_supplicant: Delete the file
/etc/wpa_supplicant/wpa_supplicant.confand restart the service. - netctl: Remove all profiles from
/etc/netctl/.
After this, reboot the system or restart the network service.
Why did Linux stop connecting to Wi-Fi after updating?
A common cause is a kernel or driver update that causes the Wi-Fi adapter to stop working. Check:
- Is the driver module loaded:
lsmod | grep -i wifi. - Is your adapter in the list of devices:
lspci -k | grep -A 3 -i networkorlsusbfor USB adapters. - Is the adapter blocked?
rfkill list.
If the driver is missing, you may need to reinstall it. For adapters Broadcom or Realtek You may need to install proprietary drivers:
# For Ubuntu/Debiansudo apt install firmware-b43-installer # For Broadcom
sudo apt install rtl8821ce-dkms # For some Realtek