Connect to Wi-Fi on GNU/Linux (terminal)
Date created: Dec 25 2021
Why?
- For everyone who wants to become a cool kid.
-
For everyone who loves working with a terminal rather than GUI.
-
For everyone who needs to feel how extensibility of the
GNU/Linux Operating System.
Commands
Make sure you can run all these commands before you get started.
-
rfkill - tool for enabling and disabling
wireless devices
-
wpa_passphrase - Generate a WPA PSK from an
ASCII passphrase for a SSID
-
wpa_supplicant - Wi-Fi Protected Access client
and IEEE 802.1X supplicant
-
ip - show / manipulate routing, network
devices, interfaces and tunnels
-
iw - show / manipulate wireless devices and
their configuration
- dhcpcd - a DHCP client
Main
- First, unlock your wifi device if it’s locked.
-
Secondly, turn on your wireless interface. In my case, the
wireless interface is
wlan0. Your wireless
interface may look different, like
wlp1s0 (predictable network interface). But to know
what does it look like, type ip a.
sudo ip link set wlan0 up
-
Thirdly, scan for SSID (wifi name) and ask your neighbor what
the password is. If it’s your wifi, go to the next step.
sudo iw dev wlan0 scan | grep SSID
-
Fourthly, generate a config file, replace your corresponding
SSID & password. In my case, SSID is
Huynh Van Tai, and the password is
hanxinhdep.
wpa_passphrase "Huynh Van Tai" "hanxinhdep" > xxx.conf
- Fifthly, connect to Wi-Fi using the config file
sudo wpa_supplicant -c xxx.conf -i wlan0 & disown
-
Finally, get the IP address & other things with the DHCP
client.
This document is licensed under the Creative Commons Zero v1.0
Universal.
Examples, recipes, and other code in this document are additionally
licensed under the Unlicense.