How to Set Up Raspberry Pi Zero W: From OS Installation to Remote Access
This step‑by‑step guide explains what a Raspberry Pi Zero W is, how to flash Raspbian onto a micro‑SD card, configure Wi‑Fi and SSH, optimize the system, install Nginx, and expose the device to the internet using ngrok, all with clear images and code snippets.
1. What is a Raspberry Pi?
Raspberry Pi (RPi) is a credit‑card‑sized micro‑computer designed for learning programming. It runs Linux and, with Windows 10 IoT, can also run Windows.
Despite its tiny size, it offers video, audio, GPIO pins, HDMI, USB, and more.
Key specifications of the Raspberry Pi Zero W
BCM2835 processor, 1 GHz, 512 MB RAM
BCM43438 Wi‑Fi / Bluetooth chip
Micro‑USB power and OTG ports
Mini‑HDMI port
Composite video and reset pins
CSI camera interface
Micro‑SD card slot for the OS
40‑pin GPIO header
Dimensions: 65 mm × 30 mm
2. Installing the system on Raspberry Pi Zero W
Preparation
You will need:
16 GB or 32 GB SanDisk micro‑SD card
A standard USB‑type‑A data cable (not Type‑C)
SD card formatting tool (e.g., SDFormatter)
Image writing tool (Win32DiskImager)
The Raspberry Pi OS image (download from the official site)
We use the Raspbian Stretch Lite image – a minimal, console‑only version.
1️⃣ Download the OS image
After downloading, unzip the archive (≈360 MB) to obtain a folder containing a .img file (~1.7 GB).
2️⃣ Write the image to the SD card
Insert the micro‑SD card into a reader, open Win32DiskImager, select the .img file, choose the correct device, and click “Write”.
3️⃣ Configure the boot partition
After flashing, the SD card shows a single boot partition (≈40 MB). Create two empty files: ssh (no extension, no content) – enables SSH on first boot. wpa_supplicant.conf – add the following (replace with your Wi‑Fi credentials):
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="your_wifi_name"
psk="your_wifi_password"
}4️⃣ Assemble and power up
Insert the prepared SD card into the Zero W, connect power via the micro‑USB cable, and wait for the LED to become steady.
Find the device’s IP address on your router (e.g., 192.168.0.104) and SSH into it (default user pi, password raspberry).
3. Optimizing the system
3.1 Change package sources
Replace the default mirrors with a domestic source (e.g., USTC):
sudo nano /etc/apt/sources.list
# comment existing lines and add:
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/raspbian stretch main contrib non-free rpi sudo nano /etc/apt/sources.list.d/raspi.list
# comment existing lines and add:
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main uiThen run:
sudo apt-get update
sudo apt-get upgrade3.2 Set timezone
sudo dpkg-reconfigure tzdata
# choose Asia → Shanghai3.3 Enable SSH on boot
Method 1 (raspi‑config):
sudo raspi-config
# navigate to Interfacing Options → SSH → EnableMethod 2 (manual): edit /etc/rc.local and add before exit 0:
/etc/init.d/ssh start4. Installing Nginx
# Install
sudo apt-get install nginx
# Start
sudo /etc/init.d/nginx start
# Restart
sudo /etc/init.d/nginx restart
# Stop
sudo /etc/init.d/nginx stopVisit http://192.168.0.104 in a browser to see the Nginx welcome page.
5. Exposing the device to the internet (ngrok / frp)
Use a tunneling service such as ngrok or frp. The author prefers the ittun build of ngrok for ARM.
Run ngrok in a screen session so it stays alive after logout:
screen -S ngrok
./ngrok tcp 22 # example commandAccess the device via the provided public address (e.g., http://zerow.ittun.com/).
6. Final notes
The Zero W can run a small website, serve via Nginx, and be accessed remotely through a tunnel. After a couple of days of operation, memory usage stays around 250 MB, CPU temperature stays between 37‑39 °C, and the device remains stable.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
