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?

Plug Micro SD card into the computer, and open the Boot partition. 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):

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

Method 2 (Using Monitor and keyboard):

Plug Micro SD card into the Raspberry Pi, boot up the Pi. After booting has finished, type in the command line to open the wifi config file: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf In the file, add to the bottom: network={ ssid="testing" psk="testingPassword" } Change “testing” with your wifi’s SSID and change “testingPassword” with your wifi’s password. Reboot: sudo reboot 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.

Boot your Pi up and connect your Ethernet cable if you haven’t already. Open your routers config site such as, 192.168.0.1 Log into your routers site with your credentials. Look for connected devices or DHCP clients or attached devices. Scroll till you find the ip address of your Raspberry Pi. On your computer, open terminal and ssh into the ip address found. After logging in, type: sudo nano /boot/wpa_supplicant.conf Paste: country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="NETWORK-NAME" psk="NETWORK-PASSWORD" } Replace NETWORK-NAME and NETWORK-PASSWORD with your wifi ssid and password. Control + X, Y, Enter 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