Cloned from: https://linuxconfig.org/setup-wireless-interface-with-wpa-and-wpa2-on-ubuntu
This article describes a simple steps to configure Wireless interface with WPA and WPA2 on Ubuntu and debian Linux. Before we can configure wireless network interface to be used with WPA and WPA2 encryption we need to install a wpasupplicant package:
# apt-get install wpasupplicant wireless-tools
Next change a permissions on /etc/network/interfaces to read/write by a root user only:
# chmod 0600 /etc/network/interfaces
Next use iwcofig command to get a name of your wireless interface:
# iwconfig
Open up /etc/network/interfaces file and add the following code to set wlan0 wireless interface to be used with DHCP:
auto wlan0 iface wlan0 inet dhcp wpa-ssid network-name wpa-psk pre-shared-key
In case you want to set your wireless interface with a static IP address add a following code into your /etc/network/interfaces file and alter it according to your needs:
auto wlan0 iface wlan0 inet static address 10.1.1.2 netmask 255.0.0.0 network 10.0.0.0 broadcast 10.255.255.255 gateway 10.1.1.1 wpa-ssid network-name wpa-psk pre-shared-key
Restart your network and you should be done:
# /etc/init.d/networking restart
Other resources:
http://askubuntu.com/questions/294257/connect-to-wifi-network-through-ubuntu-terminal
http://askubuntu.com/questions/16584/how-to-connect-and-disconnect-to-a-network-manually-in-terminal