DEV Community

Cover image for 🧠 Raspberry Pi Headless Setup Guide (SSH, VNC, Essentials)
Levis Chiri
Levis Chiri

Posted on

1

🧠 Raspberry Pi Headless Setup Guide (SSH, VNC, Essentials)

This guide walks you through setting up a Raspberry Pi (headlessly) using Raspberry Pi Imager, enabling SSH, configuring Wi-Fi, setting up VNC Viewer, fixing common issues, and using essential commands.


πŸ“₯ 1. Installing Raspberry Pi OS Using Raspberry Pi Imager

βœ… Step 1: Download Raspberry Pi Imager

βœ… Step 2: Flash the OS to the MicroSD Card

  • Insert a microSD card (β‰₯16GB).
  • Open Raspberry Pi Imager and select:

Select OS and Storage

  • Choose OS β†’ Raspberry Pi OS (Recommended)
  • Choose Storage β†’ Select your SD card

βš™οΈ Configure Wi-Fi and SSH (Optional but recommended)

  • Click the βš™οΈ (Settings) icon:

Settings

  • Set:

    • Hostname Set Hostname
    • Wi-Fi SSID & Password WiFi Config
    • Enable SSH Enable SSH
  • Save & click Write to flash.


πŸ› οΈ Step 3: Manual Headless SSH & Wi-Fi Setup (If Not Done Above)

  1. Open the boot partition on the SD card.
  2. Create empty ssh file:
touch /boot/ssh
Enter fullscreen mode Exit fullscreen mode
  1. Create wpa_supplicant.conf:
nano /boot/wpa_supplicant.conf
Enter fullscreen mode Exit fullscreen mode

Paste:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="Your_WiFi_Name"
  psk="Your_WiFi_Password"
  key_mgmt=WPA-PSK
}
Enter fullscreen mode Exit fullscreen mode
  1. Save & eject. Insert into Pi and power on.

πŸ’» 2. Connect to Raspberry Pi via SSH

πŸ” Find the IP Address

  • With monitor:
hostname -I
Enter fullscreen mode Exit fullscreen mode
  • Headless:
ping raspberrypi.local
Enter fullscreen mode Exit fullscreen mode

πŸ” SSH from PC

ssh pi@<Raspberry_Pi_IP>
# Example:
ssh pi@192.168.1.100
Enter fullscreen mode Exit fullscreen mode
  • Default user: pi
  • Password: raspberry

πŸ”„ 3. Update the Raspberry Pi

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

πŸ–₯️ 4. Enable & Configure VNC

Enable VNC Server:

sudo raspi-config
Enter fullscreen mode Exit fullscreen mode
  • Go to Interfacing Options β†’ VNC β†’ Enable

Enable VNC

  • Exit & reboot:
sudo reboot
Enter fullscreen mode Exit fullscreen mode

Install VNC Server (if needed)

sudo apt install realvnc-vnc-server realvnc-vnc-viewer -y
Enter fullscreen mode Exit fullscreen mode

Start:

vncserver
Enter fullscreen mode Exit fullscreen mode

πŸ”— 5. Connect via VNC Viewer

  • Download: VNC Viewer
  • Enter your Raspberry Pi IP (e.g. 192.168.1.100)

VNC Viewer

  • Login:
    • Username: pi
    • Password: raspberry

🧯 6. Fix: β€œCannot currently show the desktop”

Fix 1: Set a Virtual Display

sudo nano /boot/config.txt
Enter fullscreen mode Exit fullscreen mode

Uncomment or add:

hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82
Enter fullscreen mode Exit fullscreen mode

Then:

sudo reboot
Enter fullscreen mode Exit fullscreen mode

Fix 2: Restart VNC

sudo systemctl restart vncserver-x11-serviced
# or
vncserver
Enter fullscreen mode Exit fullscreen mode

Fix 3: Reinstall Desktop

sudo apt install --reinstall raspberrypi-ui-mods
sudo reboot
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ 7. Essential Raspberry Pi Commands

πŸ”„ System Update

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

πŸ” System Info

uname -a               # Kernel
vcgencmd measure_temp  # CPU Temp
df -h                  # Disk
free -m                # RAM
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Services

sudo systemctl status vncserver-x11-serviced
sudo systemctl restart vncserver-x11-serviced
Enter fullscreen mode Exit fullscreen mode

🌐 Networking

ip a
ping google.com
Enter fullscreen mode Exit fullscreen mode

πŸ“ File Ops

ls
cd /path/to/folder
mkdir new_folder
rm -r folder_name
Enter fullscreen mode Exit fullscreen mode

πŸ” Reboot/Shutdown

sudo reboot
sudo shutdown -h now
Enter fullscreen mode Exit fullscreen mode

🌐 8. Set Static IP (Optional)

sudo nano /etc/dhcpcd.conf
Enter fullscreen mode Exit fullscreen mode

Add:

interface wlan0
static ip_address=192.168.1.150/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
Enter fullscreen mode Exit fullscreen mode

Save and reboot.


πŸ“¦ 9. Install Useful Software

sudo apt install python3 python3-pip git nodejs npm -y
Enter fullscreen mode Exit fullscreen mode

⚑ 10. Enable GPIO for Projects

sudo raspi-config
Enter fullscreen mode Exit fullscreen mode
  • Go to Interfacing Options β†’ Enable GPIO

Install libraries:

sudo apt install python3-gpiozero python3-rpi.gpio -y
Enter fullscreen mode Exit fullscreen mode

Test:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
print("GPIO Ready!")
Enter fullscreen mode Exit fullscreen mode

🌍 11. Optional: Web Server Setup (Apache)

sudo apt install apache2 -y
sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

Access from browser:

http://<Raspberry_Pi_IP>
Enter fullscreen mode Exit fullscreen mode

project files, or embed code repos.

Heroku

Amplify your impact where it matters most β€” building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

If you found this post helpful, please leave a ❀️ or a friendly comment below!

Okay