How to setup wifi from shell

less than 1 minute read

If you’ve accidentally broken the desktop environment while updating system you probably need access to wisdom of google under terminal. How to do it? Well it’s simple if you know what to do :smile:

Most of search results suggests iwconfig, but there is a small problem: it doesn’t support anything stronger than WEP. Here wpa_supplicant comes to the rescue. The simplest way to connect to wifi consists of couple of simple steps:

  1. find available networks (only if you don’t know SSID of the network)
    sudo iwlist wlan0 scan
    
  2. generate the config with wpa_passphrase:
    wpa_passphrase <ssid> <password> > wpa_supplicant.conf
    
  3. run wpa_supplicant with the created config
    wpa_supplicant -iwlan0 -c wpa_supplicant.conf
    
  4. Obtain network settings through DHCP client:
    dhclient wlan0