Pete LePage

Thoughts on web development, life, and photography.

Raspberry Pi Headless Setup

I recently had to create a new Raspberry Pi image, and thankfully you can now do it without the need to ever plug the Pi into a keyboard or monitor!

Create & configure the SD card #

  1. Use the Raspberry Pi Imager to create a Raspberry Pi OS Lite SD card.
  2. Mount the SD card.
  3. Enable SSH by creating an empty file named ssh in the boot partition of the SD card. (source)
  4. Configure the wireless network by dropping the wpa_supplicant.conf file into the boot partition of the SD card. (source)
  5. Unmount SD card from computer, and boot Raspberry Pi.

Initial Configuration #

  1. SSH into raspberrypi, username: pi password: raspberry
  2. Run sudo raspi-config
    1. Run Update to update to the latest raspi-config tool.
    2. Set System Options, including password, hostname, and auto-login.
    3. Set Display Options, including screen blanking.
    4. Set Performance Options, including Fan, and GPU Memory (16).
    5. Set Localization Options.
    6. Set Advanced Options, including Expand File System.
    7. Exit & reboot.
  3. SSH into Raspberry Pi using new hostname & password.

Disable HDMI CEC (optional) #

I don’t want my Pi to turn the TV on when it boots, so I disable the HDMI CEC functionality.

  1. Disable CEC commands via HDMI. (source)

    echo "hdmi_ignore_cec=1" | sudo tee -a /boot/config.txt

  2. Disable CEC active source message being sent during bootup.

    echo "hdmi_ignore_cec_init=1" | sudo tee -a /boot/config.txt

Edit dotfiles #

  1. Create .bash_prompt
  2. Add source .bash_prompt to bottom of .bashrc

Harden security on system #

  1. Follow steps at

Note: If you switch username, you’ll need to edit the dotfiles again.

Enable SSH access via key #

  1. If you haven’t already, create an SSH key on the remote computer with:


  2. From the remote computer, copy key to account on the Pi:

    ssh-copy-id pi@HOSTNAME

  3. SSH into the Pi and disable password authentication:

    echo "PasswordAuthentication no" | sudo tee -a /etc/ssh/sshd_config

Update and install required software #

Update existing software #

  1. sudo apt -y update && sudo apt -y full-upgrade

Install additional packages #

  1. sudo apt -y install git git-core
  2. sudo apt -y install lynx netatalk libssl-dev sshfs wiringpi
  3. sudo apt -y install alsa-utils mpg321 mplayer
  4. sudo apt -y install bluetooth bluez libbluetooth-dev libudev-dev
  5. sudo apt -y install libavahi-compat-libdnssd-dev libcap2-bin libtool-bin
  6. (optional) sudo apt -y install python-setuptools python-dev python-rpi.gpio
  7. (optional) sudo apt -y install android-tools-adb

Install Node via NVM #

  1. Install nvm

  2. Add NVM to path:

    source ./.bashrc

  3. Install a current version of Node:

    nvm install 14

  4. (optional) Install forever:

    npm install -g forever