Skip to content

Instantly share code, notes, and snippets.

@samjf
Last active December 22, 2021 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samjf/d31e4dd1a4931a899f56b385e893cddf to your computer and use it in GitHub Desktop.
Save samjf/d31e4dd1a4931a899f56b385e893cddf to your computer and use it in GitHub Desktop.
Rasbperry Pi Headless Instructions

Instructions on how to setup RaspberryPi without any monitor / HDMI. You should only need to have the MicroSD, USB power, and a Pi with wireless.

I tested this on a Raspberry Pi Zero 2 W

Prepare the image

  • Go here and get RaspberryPi Imager https://www.raspberrypi.com/software/
  • Start up the Imager app.
  • Install the recommended image or whatever you want
    • will need a micro SD card to write the OS image to.
  • Once the image has been copied over to the SD card then make a file wpa_supplicant.conf under /boot on the SD with the content.
    • in my case for a Mac this is located at /Volumes/boot
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
country=<Insert 2 letter ISO 3166-1 country code here>
update_config=1

network={
 scan_ssid=1
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
 proto=RSN
 key_mgmt=WPA-PSK       
 pairwise=CCMP       
 auth_alg=OPEN  
}

To add an encrypted password instead of a plain one:

  • install wpa_passphrase
  • run wpa_passphrase <SSID>
  • you'll be propted for a password and it'll output the network block for you.
  • if you do this then don't quote the password, but put it in config without the quotes!
  • it appears this file we are making is removed after the first boot, so likely not much of a risk here anyways.

Add a file called ssh to the /boot folder too. This will enable SSH.

  • touch ssh

Connect

Plug in the SD Card and the power and wait for a bit (~5 mins).

Now we can try ssh in. Take note of the warning:

If installing remotely via SSH, connect to your Raspberry Pi by name rather than by IP address, e.g. ssh pi@raspberrypi.local, as the address of your Raspberry Pi on the network will probably change after installation. You should also be ready to add screen and keyboard if needed in case you lose contact with your Raspberry Pi after installation.

Default credentials are:

Default username: pi User management in Raspberry Pi OS is done on the command line. The default user is pi, and the password is raspberry. You can add users and change each user’s password.

So for the final step we can: ssh pi@raspberrypi.local

Setup a Graphical Remote Desktop

On the Pi do the following to install VNC for remote desktop (see docs):

sudo apt update
sudo apt install realvnc-vnc-server realvnc-vnc-viewer

Now we have to enable the VNC Server via raspi-config

sudo raspi-config

The navigate to Interfacing Options > VNC. Enable it and finish.

Now, if the Pi is setup to be headless (as we are in this guide) then we must start a virtual desktop by simply running the command vncserver. This command will output various pass phrases for confirmation, and also the address to connect to (an IP with a screen number).

Install the viewer client from here: https://www.realvnc.com/en/connect/download/viewer/

Start 'er up and chuck in the address. You'll be prompted for your username / password to connect.

You'll be guided through some setup steps, you may have done some already, so skip where you can / want.

Done & Done.

See also: Headlesss setup instructions How to setup encrypted wireless pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment