Headless Wi-Fi on Ubuntu-Like Linux? Use `nmcli`
A GUI is not required to configure Wi-Fi on Ubuntu, Debian, or Linux Mint. If NetworkManager is running, nmcli can scan for networks, create a persistent connection profile, and reconnect automatically after reboot.
Scan for nearby networks:
nmcli radio wifi on
nmcli device wifi rescan
nmcli device wifi list
Connect without putting the password in shell history:
read -rsp 'Wi-Fi password: ' WIFI_PASSWORD
echo
sudo nmcli device wifi connect 'SSID_NAME' \
password "$WIFI_PASSWORD" \
ifname wlan0
unset WIFI_PASSWORD
Replace SSID_NAME and wlan0 with the network name and wireless interface shown by nmcli device status. NetworkManager saves the new profile and normally enables autoconnect automatically.
Verify the address, route, and connectivity:
nmcli device status
nmcli connection show
ip addr show wlan0
ip route
ping -c 3 1.1.1.1
For a hidden network, add hidden yes; for an open network, omit the password argument. Do not switch networks over SSH unless you have another way back in, because the current connection may drop immediately.