Advertisements

How to enable remote configuration of your Raspbian Stretch Lite over WiFi on first boot

Two of the good features of Raspbian Stretch Lite is that it allows us to enable the SSH server and connect to our WiFi network before it boots up for the first time.

Combining these two features is useful for projects based on Raspberry Pi Zero W as we can configure Raspbian Stretch Lite via SSH without connecting extra peripherals to it.

This post documents how you can enable remote configuration of your Raspbian Stretch Lite over WiFi on first boot.

Writing the Raspbian Stretch Lite image to the SD card first

Prior to enabling remote configuration of our Raspbian Stretch Lite over WiFi on first boot, you need to write the image to the SD card first.

I usually use Etcher on my MacBook Pro to install the operating system image onto the SD card.

If you are using a windows machine, you can use Win32DiskImager to install the operating system.

If you are using a Linux desktop, you should be able to Etcher to install the operating system.

Creating an empty ssh file and copied to the root folder

Once you had written the Raspbian Stretch Lite image to the SD card, the next step is to signal to Raspbian Stretch Lite that you want to enable the SSH server on first boot.

To do so, simply create an empty file named as "ssh" and copied it to the root directory of the SD card:

Raspbian Stretch Lite 20171212 boot with ssh file

Sitewide-10usd468x60

Creating a wpa_supplicant.conf file that contains your WiFi network configuration

Once you got the ssh file into the root directory of the SD card, use a text editor to create a file named as "wpa_supplicant.conf" with content similar to the following:

country=SG
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
 
network={
        scan_ssid=1
        ssid="the_2.4-hz-wireless-network"
        psk="the_2.4-hz-wireless-network_password"
        proto=WPA
        key_mgmt=WPA-PSK 
}

You need to change the values for "country", "ssid", "psk", "proto" and "key_mgmt" to match your 2.4 Ghz Wireless network setup.

The name of your wireless network is represented by "ssid".

The password to connect to your wireless network is represented by "psk".

The communication protocol used by your router is represented by "proto". Some acceptable values are WPA and RSN.

The key management protocol used by your router is represented by "key_mgmt". Some acceptable values are "WPA-PSK" and "WPA-EAP".

The values for "proto" and "key_mgmt" are commonly set to WPA and WPA-PSK.

Copying the wpa_supplicant.conf file to the root directory of the SD card

Once you had create the wpa_supplicant.conf file with your WiFi network configurations, you will then copy the file into the SD card:

Raspbian Stretch Lite 20171212 boot folder with wpa_supplicant and ssh

Getting the IP address that your Raspbian Stretch Lite got from your router

Once you had copied over the wpa_supplicant.conf file into the SD card, you can then put it into the SD card slot of your Raspberry Pi. When you provide power to your Raspberry Pi, you can then look at your router's address allocation table and find an entry with the name raspberrypi.

Connecting to your Raspbian Stretch Lite via SSH

With the IP address given by your router, you can then SSH into your Raspbian Stretch Lite to configure it. Suppose the IP address is 192.168.1.123, you can then enter the following command into your favourite terminal program to access your Raspbian Stretch Lite:

ssh pi@192.168.1.123

The "pi" user is the default user that is created for us to configure our Raspbian Stretch Lite. When Raspbian Stretch Lite prompts for a password, enter "raspberry" without the quotes. This will get you into Raspbian Stretch Lite to perform further configurations.

Advertisements

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people.

Udemy.com Homepage 300x250
Advertisements