How to set up Wi-Fi USB dongle on Raspberry Pi using the terminal + Android Tethering

It is relatively simple and cheap to add Wi-Fi connectivity to your Raspberry Pi. You only need to buy a Wi-Fi USB dongle and make sure that is compatible with GNU/Linux. On you can find a list of compatible Wi-Fi adapters.

In this tutorial, I am using Edimax EW-7811UN available for less than 10 £ on Amazon.

Edimax EW-7811UN 150Mbps Wireless Nano USB Adapter

Before to start with the actual setup, you need to take note of the following details of your Wi-Fi connection:

  • Network SSID
  • Wireless password
  • Security (e.g.: WPA2-PSK)

In order to make this project a little more interesting, I am going to use my Nexus 4 as a Wi-Fi Hotspot. Therefore, I am going to share my device’s 3G data connection as a portable Wi-Fi hotspot.

(If you are not using an Android device as Hotspot just skip the following section)

On your Android device (This steps apply to Nexus 4, Galaxy Nexus, Nexus 7 (2013), and Google Play edition devices):

  1. Go to Settings > Under the section Wireless & networks > More > Tethering & portable hotspot.
  2. Go to Set up Wi-Fi hotspot and type your Network SSID, Security (e.g. I selected WPA2-PSK), Password > Save
  3. Tick Portable Wi-Fi hotspot

After a moment, the device starts broadcasting its Wi-Fi network name (SSID). Once you want to stop sharing your data connection, just untick Portable Wi-Fi hotspot.

Now, it’s time to go back to our Raspberry setup.

It is always good practice to update the system to the latest available software. Open your Terminal and type:

sudo apt-get update
sudo apt-get install

Now, type the following command to open the interfaces configuration file:

sudo nano /etc/network/interfaces

You should see the following lines:

auto loiface lo inet loopback
iface eth0 inet dhcp

This is the default setup of your Ethernet connection (eth0). We need to add the following lines for the new Wireless connection that we want to set up (wlan0):

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Press Ctrl-x to save and exit.

In the terminal enter the following command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Replace all the content of the file with the following:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev



# scan_ssid type can be: value of 1 means broadcast and value of 2 means hidden


# Protocol type can be: RSN (for WP2) and WPA (for WPA1)

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)

# Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)


The lines with # are only comments that should guide you. When you’re done with the editing, press CTRL+x to save and exit.

Now you only need to reboot in order to load the new network set up.

Raspberry will connect automatically during the boot to the Wi-Fi network.