Setting up wifi on a headless Raspberry Pi

Wifi on a headless Pi:

In this tutorial I am using Raspbian GNU/Linux 9 (stretch).  WARNING: These ways of setting up wifi may change as newer version of Raspbian are released!

Setting up wifi via command line is pretty easy using ssh or from adding a file to your Raspberry Pi boot partition. Here’s how.

Hardware needed:

  • Raspberry Pi
  • 8GB Micro SD Card with Raspbian Lite
  • Monitor or another computer
How do I start?

  1. Plug Micro SD card into the computer, and open the Boot partition.
  2. Add an empty file to the called ssh. Make sure there is no extension added to the file for example ssh.txt.

2 out of the 3 methods is setting up wifi via command line. This can be particularly useful if you are using Raspbian Lite.

Method 1 (Before First Boot):

  1. Create a file in the boot partition named wpa_supplicant.conf.
  2. Open the file and paste:
    country=GB
    update_config=1
    ctrl_interface=/var/run/wpa_supplicant
    
    network={
     scan_ssid=1
     ssid="RouterName"
     psk="Security"
    }
  3. Replace “GB” with your country code.
  4. Replace “RouterName” with your wifi SSID and change “Security” with your wifi password.
  5. Boot up the Raspberry Pi and check if everything is working by pinging google: ping google.com

Method 2 (Using Monitor and keyboard):

  1. Plug Micro SD card into the Raspberry Pi, boot up the Pi.
  2. After booting has finished, type in the command line to open the wifi config file: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
  3. In the file, add to the bottom:
    network={
        ssid="testing"
        psk="testingPassword"
    }
  4.  Change “testing” with your wifi’s SSID and change “testingPassword” with your wifi’s password.
  5. Reboot: sudo reboot
  6. Everything should work now. Try Pinging google: ping google.com

Method 3 (via ethernet cable):

So you have already connected your Raspberry Pi to your router with a ethernet cable? Well don’t worry.

  1. Boot your Pi up and connect your Ethernet cable if you haven’t already.
  2. Open your routers config site such as, 192.168.0.1
  3. Log into your routers site with your credentials.
  4. Look for connected devices or DHCP clients or attached devices.
  5. Scroll till you find the ip address of your Raspberry Pi.
  6. On your computer, open terminal and ssh into the ip address found.
  7. After logging in, type:
    sudo nano /boot/wpa_supplicant.conf
  8. Paste:
    country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
        ssid="NETWORK-NAME"
        psk="NETWORK-PASSWORD"
    }
  9.  Replace NETWORK-NAME and NETWORK-PASSWORD with your wifi ssid and password.
  10. Control + X, Y, Enter
  11. Reboot, remove the ethernet cable, wait a couple of seconds and test to see if wifi works by pinging google.com:
    ping google.com

Any issues? Post them in the comments!

 

Raspberry Pi images

 

4 Replies to “Setting up wifi on a headless Raspberry Pi”

  1. Hi there, You have done a fantastic job. I’ll certainly digg it and personally recommend to my friends.

    I am confident they’ll be benefited from this site.

Leave a Reply

Your email address will not be published. Required fields are marked *