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.

Historical instructions for the Raspbian releases used in 2017–2018; do not assume that every newer Raspberry Pi OS release uses the same boot-partition setup.

1. Wi-Fi 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
}

Configuration fields:

  • ssid: the Wi-Fi network name.
  • psk: the Wi-Fi password; replace the example value.
  • priority: connection priority; higher values take precedence.
  • scan_ssid=1: scan for a hidden network.
  • key_mgmt=WPA-PSK: the WPA/WPA2 personal-network setting used above.
  • key_mgmt=NONE: used for an open network. The old WEP example also listed this value, but omitted the required WEP key settings and was not a complete WEP configuration.

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

2. Enable SSH

As with the Wi-Fi 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 Wi-Fi but no wired network adapter or standard USB ports for directly connecting a keyboard and mouse.

Sources and credits

Type: Reposted and edited

Original: Configure Raspberry Pi Wi-Fi and SSH without a screen or keyboard (September 13, 2017)

Author or publisher: Raspberry Pi Lab (NXEZ).

Note: Adapted from the article above. This archive retains the older Raspbian examples with corrected code and paragraph formatting.

Published 06/26/2018 · Krunk Zhou

Join the conversation