Published on

Headless Pi - For dummies

Today, my Raspberry Pi 4 arrived. Pretty exited to finally own one. I used Raspberry Pi 3 & 4 occasionally in my Uni days previously. Now, I would like to have a little server running at home for various projects. I didn't find the needs to make it like a 'computer', ie with monitor, mouse & keyboards attached. Controlling it via terminal using host machine is fine.

raspberry-pi-cytron

For the host machine, I'm using Windows 11. Connected to the same Wifi network as the Pi.

Create boot media

Grab a microSD card; 16-32Gb is fine. Download Raspberry Pi Imager, or other imager tool like Balena Etcher to burn the OS Image to the microSD card. I'm using latest Raspberry Pi Bookwork 64-bit OS. Before installing, customize the OS by set the hostname, Wifi SSID & Password, enabling SSH etc. For more info, read the docs here.

Once the OS is installed, remove the microSD card from the host and insert it to the Raspberry Pi. Power it up. Wait for a few minutes for the first boot.

Connect over SSH

The Raspberry Pi will automatically connect to the Wifi network. From the host machine, try pinging the Pi for confirmation.

Open your Terminal and run:

> ping raspi.local

Pinging raspi.local [192.168.0.14] with 32 bytes of data:
Reply from 192.168.0.14: bytes=32 time=60ms TTL=64
Reply from 192.168.0.14: bytes=32 time=24ms TTL=64
Reply from 192.168.0.14: bytes=32 time=7ms TTL=64
Reply from 192.168.0.14: bytes=32 time=12ms TTL=64

Ping statistics for 192.168.0.14:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 7ms, Maximum = 60ms, Average = 25ms
note

raspi is the hostname I set when creating the boot media. You can replace it with your hostname. The discovery is possible because the Raspberry Pi is using mDNS that works out of the box using avahi. If you can't ping it, try to find the IP address of the Pi using your router admin page.

Now, SSH into the Pi:

ssh iqmal@raspi.local
note

iqmal is the username I set when creating the boot media.

You will be prompted to enter the password. Enter the password you set when creating the boot media. For first time connection, you may be asked to trust the device etc. Then, you should now be connected to the Pi.

Login SSH raspberry pi

Great, now you access the the Pi terminal which you can install software, configure etc.

Enable VNC

This is optional step if you want to use the Raspberry Pi by its GUI desktop interface. This desktop interface is what you'll see if you connect your Pi to the external monitor. Since, we don't have any monitor connected physically, we can access it remotely using VNC (Virual Network Computing).

To enable VNC, run the following command:

sudo raspi-config
warning

I notice that, when I enabling VNC after I do the set default boot mode to CLI, it will create VNC config based on X11 backend, not wayland. This will cause the VNC viewer to show blank screen.

Navigate to Interfacing Options > VNC > Yes. Reboot the Pi.

VNC raspi config

On the host machine, download TigerVNC viewer.

Open TigerVNC viewer and enter the IP address/hostname of the Pi.

VNC Tiger Viewer

Then, enter the login username & password.

VNC Login

You should now see the Raspberry Pi desktop interface.

VNC Rasperry pi

Set default boot mode to CLI

This is also optional step since we are not using GUI interface that much. We can change the default boot mode to CLI (Command Line Interface) to save some resources. We can always start a GUI anytime.

sudo raspi-config

Navigate to System Options > Boot / Auto Login > Console Autologin. Reboot the Pi.

boot mode raspi config

To start the GUI interface if needed, from SSH terminal, run:

sudo systemctl start lightdm

Connect VNC and you should see the desktop interface again.