To use WPA2 pre-shared key on the Raspberry Pi, you will first need to add a network configuration to “/etc/wpa_supplicant/wpa_supplicant.conf”. Note the lack of space in “network={“.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Your SSID Here"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="YourPresharedKeyHere"
}
After you have modified wpa_supplicant.conf, you will need to change the “wlan0” section of “/etc/network/interfaces”. For a static IP, it will look like this:
# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 10.1.2.20
netmask 255.255.255.0
network 10.1.2.0
gateway 10.1.2.1
For DHCP, it will look like this:
# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
After that, you will need to bring up the “wlan0” interface using “ifup”:
You may have to bring the interface down and then back up:
# sudo ifdown wlan0
# sudo ifup wlan0
You may see messages like this: