Raspberry Pi / Computer projects

Setting Up Wi-Fi and SSH on a Raspberry Pi Before Its First Boot

This isn't exactly a new feature. Shortly after the Raspberry Pi 3B was released, the official Raspberry Pi operating system, Raspbian, added a way to configure Wi-Fi before the first boot.

1. WiFi network configuration

Before starting the Raspberry Pi, you can edit the /boot/wpa_supplicant.conf file to set the Wi-Fi SSID and password. The Raspberry Pi will then read the wpa_supplicant.conf configuration file on startup and connect to the Wi-Fi network. The procedure is simple: insert an SD card flashed with Raspbian into your computer. Create a new wpa_supplicant.conf file in the boot partition, which corresponds to the Raspberry Pi's /boot directory. Enter the configuration shown below and save the file.

country=CN

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

update_config=1

network={

ssid="KRUNK-WiFi-A"

psk="12345678"

key_mgmt=WPA-PSK

priority=1

}

network={

ssid="KRUNK-WiFi-B"

psk="12345678"

key_mgmt=WPA-PSK

priority=2

scan_ssid=1

}

Notes and WiFi configuration examples for different security types: #ssid: the network's ssid #psk: password #priority: connection priority; a larger number means higher priority (cannot be negative) #scan_ssid: set this to 1 when connecting to a hidden WiFi network. If your WiFi has no password: key_mgmt=NONE. If your WiFi uses WEP encryption:

key_mgmt=NONE

If your WiFi uses WPA/WPA2 encryption

key_mgmt=WPA-PSK

If you are not sure which encryption mode your WiFi uses, open /data/misc/wifi/wpa/wpa_supplicant.conf in Root Explorer on an Android phone to check its WiFi information.

2. Enable SSH

As with the WiFi configuration, create a file in the boot partition. It can be empty; name it ssh, in lowercase and without any extension. When the Raspberry Pi starts and detects this file, it automatically enables SSH. You can then log in to your router to find the Pi's IP address and connect over SSH. If you want to use a remote desktop, install xrdp over SSH and connect to the Raspberry Pi using the Windows Remote Desktop client. This trick is especially useful for the Raspberry Pi Zero W, which has built-in WiFi but no wired network adapter or standard USB ports for directly connecting a keyboard and mouse.

Source: Raspberry Pi Lab

Published 06/26/2018 · Krunk Zhou

Join the conversation