Not all Debian systems have a GUI, and even though using WiFi on a server isn’t common, there are plenty of instances where you’re using WiFi with a headless setup, like on a Raspberry Pi. It’s not difficult to connect using only the tools provided out of the box in Debian.
In this tutorial you will learn:
- How to Scan for a Network
- How to Generate a WPA_Supplicant Config
- How to Set up a WPA_Supplicant Config File
- How to Connect to Your WiFi
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Debian 10 Buster |
Software | WPA_Supplicant |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Scan for a Network
Before you can connect to your network, you need to find exactly what you’re connecting to. If you already know the name of the WiFi network that you want to connect to, this section isn’t necessary, but if you’re trying to connect without knowing the SSID off hand, this will help you find it.
First, find the name of your WiFi interface. Run the following, and write down the wireless interface. From here on, this guide will call it wlan0
, but yours will probably be different.
$ ip a
Next, you can scan the networks in the area to find the SSID you want to connect to. As root or with sudo
, run:
$ sudo iwlist wlan0 scan | grep -i ssid
Find the name of the network you want to connect to, and write it down.
Generate a WPA_Supplicant Config
WPA_Supplicant can generate its own configuration, or the beginnings of one, including encrypting your network passowrd, so it’s not stored in plain text.
$ sudo wpa_passphrase networkname password > /etc/wpa_supplicant/wpa_supplicant.conf
Set up a WPA_Supplicant Config File
Now, use your favorite text editor to open /etc/wpa_supplicant/wpa_supplicant.conf
.
Take a look at the network
block that was generated. It contains your network’s name and both the plain text password and the encrypted one. The plain text is just there to show you what you entered, and it’s commented out. Delete that line.
Above the network
block, place the following line. It will allow users in the wheel
group to manage WPA_Supplicant.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
Turn your attention back inside the network
block now. If you’re connecting to a hidden network, add the line below after your password.
scan_ssid=1
Then, add in the protocol and key management settings for WPA2. If you’re using anything else, stop and upgrade to WPA2.
proto=RSN key_mgmt=WPA-PSK
Next, tell WPA_Supplicant to use CCMP instead of TKIP. Again, if you’re using TKIP, stop. It’s proven itself not to be secure.
group=CCMP pairwise=CCMP
The last thing you should include is the priority. If you’re managing multiple networks here, give the highest priority value to the ones you want to connect to first.
priority=10
Save your configuration, and exit.
Connect to Your WiFi
In order to connect, you’re going to need to restart WPA_Supplicant. It’s a service, so you can restart it with systemctl
.
$ sudo systemctl restart wpa_supplicant
Give it a few seconds to connect, and check that you’re connected by running ip a
again. You should see a local IP next to your wireless interface this time.
Conclusion
Because you set up your connection manually with a configuration, this should continue working until you change something yourself. You can easily connect to multiple networks, and keep them organize with this method too.