raspberry pi connect to wifi via terminal
Setting country (Important for legal reasons):
If this has been done before then skip this section (Only needs to happen once)
sudo raspi-config
Localisation Options > Set legal wireless channels for your country (this is important)
Finish (Will require reboot)
Scanning for networks:
If you know your networks SSID and other relevant info, skip this section
iwlist wlan0 scan
Find 'ESSID' which will contain the name of your network
Find 'IE: IEEE 802.11i/WPA2 Version 1' (This guide should work for WPA and WPA2 but maybe not for WPA2 enterprise, for WEP hex keys, see here: https://www.freebsd.org/cgi/man.cgi?query=wpa_supplicant.conf&sektion=5&apropos=0&manpath=NetBSD+6.1.5)
Find the password to the network (You need to figure that one out on your own ;)
Adding network:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
For each network that you want to add
network={
ssid="CoolNetworkName"
psk="SecureNetworkPassword"
}