Skip to content

Instantly share code, notes, and snippets.

@wemakefuture
Forked from rjcorwin/wpa2-wifi-connect.sh
Created March 11, 2018 23:24
Show Gist options
  • Save wemakefuture/63e110f74b6c951df5a98ea6fed14668 to your computer and use it in GitHub Desktop.
Save wemakefuture/63e110f74b6c951df5a98ea6fed14668 to your computer and use it in GitHub Desktop.
A simple `wifi` command for Debian that will connect you to a WPA2 WiFi network
#!/bin/sh
## A simple `wifi` command for Debian that will connect you to a WPA2 WiFi network
## usage:
## sudo ./wpa2-wifi-connect.sh <ssid> <pass>
ifdown wlan0
# build the interfaces file that will point to the file that holds our configuration
rm /etc/network/interfaces
touch /etc/network/interfaces
echo 'auto lo' >> /etc/network/interfaces
echo 'iface lo inet loopback' >> /etc/network/interfaces
echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
echo 'allow-hotplug wlan0' >> /etc/network/interfaces
echo 'iface wlan0 inet manual' >> /etc/network/interfaces
echo 'wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
echo 'iface default inet dhcp' >> /etc/network/interfaces
# build the supplicant file that holds our configuration
rm /etc/wpa_supplicant/wpa_supplicant.conf
touch /etc/wpa_supplicant/wpa_supplicant.conf
echo 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev' >> /etc/wpa_supplicant/wpa_supplicant.conf
echo 'update_config=1' >> /etc/wpa_supplicant/wpa_supplicant.conf
wpa_passphrase $1 $2 >> /etc/wpa_supplicant/wpa_supplicant.conf
ifup wlan0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment