This post assumes that you are already familiar with connecting Windows or Mac OS to an existing accesspoint. It also assumes that you have a working wireless network card. If you are looking for an inexpensive wifi card that you can attach to a USB 2.0 port, take a look at my previous post (CSL 300 Mbit/s wifi adapter with Debian 8 Jessie). You might have to install additional firmware packages.
Here is a list of supported wifi devices by the Linux kernel:
Check with iwconfig that there is a working WiFi device on your computer:
$ iwconfig wlan0 IEEE 802.11bgn ESSID:off/any Mode:Managed Access Point: Not-Associated Tx-Power=15 dBm Retry short limit:7 RTS thr:off Fragment thr:off Encryption key:off Power Management:on
This tells us that there is a WiFi device called "wlan0" capable to connect to any 802.11b/g/n accesspoint.
There are 2 ways to configure wireless networks in Linux:
- Using the graphical tool "NetworkManager"
The preferred method if you are using a graphical desktop environment. Very similar to Windows or Mac OS and easy to use.
- On the command line using "wpa_supplicant"
Only recommended for experienced Linux users.
Both of them are included in every modern Linux distribution and have advantages and disadvantages which I will explain later in this post. You should not mix both methods, just decide for one of them and stick with it. So if you already use NetworkManager to manage ethernet connections, it is easy to add one or more WiFi connections.
Both NetworkManager and the native command line method rely on the package "wpa_supplicant" (or "wpasupplicant") to actually use a wifi network. Nevertheless I will use the term "wpa_supplicant" to refer to the command line method.
There is a plethora of additional graphical network tools in Linux, e.g. graphical front ends for wpa_supplicant. Once you know the basics of wpa_supplicant it is easy to use other tools too. Therefore in this post I will only describe how to configure wpa_supplicant on the command line.
2. Encryption Protocols
WPA2 (802.11i) is today's standard for wireless data encryption. It uses 2 different keys for encrypting traffic between accesspoint and client stations.
|Name||Description||Configuration Option||Rekeying Interval (Default Value)||Notes|
|PTK ("Pairwise Transient Key":)||- Consists of several other keys / fields used to encrypt data and distribute GTK to client stations|
- Unique to every client station
- Only used for unicast traffic
|"wpa_ptk_rekey" in wpa_supplicant.conf||?|
|GTK ("Group Transient Key")||- Generated by accesspoint and sent to client stations|
- Shared by all client stations
- Only used for multicast, / broadcast traffic
|"Group Key Interval" in accesspoint configuration|
rekey interval is not configurable in NetworkManager or wpa_supplicant
|30 seconds||- Not configurable in NetworkManager or wpa_supplicant
- Rekeying is completely up to accesspoint, so there is no way to print the rekey interval on client station (wpa_cli or nmcli)
- wpa_supplicant generates log entries like the following:
wpa_supplicant: wlan0: WPA: Group rekeying completed with 00:2a:0e:ab:cd:ef [GTK=CCMP]
Both keys are then used to encrypt traffic between accesspoint and client stations. There are 2 protocols for symmetric data encryption:
- TKIP (Temporal Key Integrity Protocol)
based on RC4
insecure and obsolete
use only in combination with additional encryption layers like VPN or SSH tunnels
- CCMP (CCM Mode Protocol)
based on AES
3. Authentication Methods
There are 2 different authentication methods for wireless networks:
- All users share the same single key
Primarily used for a smaller number of client stations, e.g. in home networks or small guest networks
- Every user has his own username / password (or unique client certificate)
Useful for a larger number of client stations, e.g. in corporate environments or where you have a lot of guest users
WPA2 Personal / PSK (Preshared Key)
The same key (8 - 63 characters) must be configured on accesspoint and client stations. It is directly used as PMK (Pairwise Master Key) by accesspoint, and then used to calculate PTK (Pairwise Transient Key). PTK is then used to calculate GTK.
WPA2 Enterprise / 802.1x
Actual authentication is not performed by the accesspoint, but by a 3rd party server called "authentication server". This is usually a Radius server running "freeradius".
Even though authentication is performed by a separate authentication server, it only knows the MK (Master Key) and its derived PMK (Pairwise Master Key). The PMK is transferred (moved, not copied) from the authentication server to the accesspoint and used to calculate a PTK (Pairwise Transient Key). So the authentication server has no access to neither PTK nor GTK and therefore cannot decrypt traffic (unicast or multicast) between accesspoint and client stations.
- WPA2 Enterprise usually requires a username / password combination for authentication
(authentication methods LEAP, FAST, PEAP, and TTLS)
- Using TLS as the authentication method the client authenticates with a client X.509 certificate.
- The client itself may use a CA certificate to verify that it is connecting to the right accesspoint (similar to HTTPS connections in webbrowsers).
NetworkManager is part of every modern LInux distribution. After a standard installation of Linux you will see a network icon in the system bar of desktop environment. If you click on it you will see a list of options to configure NetworkManager.
Connection settings that you make in the GUI are stored as plain text files under /etc/NetworkManager/system-connections . (Explanation of all settings:
In addition to configure wireless networks, NetworkManager offers some other useful features:
- You can integrate NetworkManager with desktop encryption tools like kwallet to prevent passwords from being saved in plain text to the configuration files.
- You can integrate NetworkManager with firewalld to automatically assign WiFi networks to firewall zones.
- You can configure NetworkManager to automatically use a VPN connection once you are connected to a specific WiFi network.
Automatically connect to this network when it is available
In most cases leave this unchecked. Otherwise there might be occasions where you involuntary connect to the WiFi network.
All users may connect to this network
Only check this option if you want to share your wifi configuration with other Linux user accounts.
Automatically connect to VPN when using this connection
Useful when using an insecure public WiFi hotspot that you only want to use in combination with a VPN tunnel.
If you are using firewalld and firewall-config, you may associate this WiFi network with a specific firewall zone. If empty the default firewall zone will be used automatically.
The dialog box layout is a little bit misleading because this field has nothing to do with the previous "Firewall zone" field. If there is more than one of the "Automatically connect to this network ..." wifi networks available, "Priority" defines the order in which those networks will be activated. The first successful connection will be used.
NetworkManager can also be controlled from the command line with "nmcli".
Display current state of NetworkManager service $ nmcli g STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN connected full enabled enabled enabled enabled Show a list of all network connections $ nmcli c mynetwork abababab-cdcd-12cc-bbef-1212121212ab 802-11-wireless wlan0 Stop wifi network $ nmcli c down id mynetwork Start wifi network $ nmcli c up id mynetwork
wpa_supplicant runs as a service process in the background. Connections are stored by default in /etc/wpa_supplicant/wpa_supplicant.conf .
Sample configuration file with detailed explanations:
The wpa_supplicant background service can be controlled from the command line with "wpa_cli".
Display list of all command line parameters $ wpa_cli help Display a list of configured networks $ wpa_cli list_networks 0 mynetwork 0a:ab:ee:ef:2a:ef [CURRENT] Start wifi network $ wpa_cli enable_network 0 Stop wifi network $ wpa_cli disable_network 0 Show current wifi connection status $ wpa_cli status