1.Create file and add wifi name and creds (vi /etc/wpa_supplicant.conf)
network={
ssid="ssid_name"
psk="password"
}
2.Connect
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
sudo dhclient wlan0
More : https://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa-wifi-network-using-the-command-line
https://askubuntu.com/questions/294257/connect-to-wifi-network-through-ubuntu-terminal