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 #
- Use the Raspberry Pi Imager to create a Raspberry Pi OS Lite SD card.
- Mount the SD card.
- Enable SSH by creating an empty file named
ssh
in the boot partition of the SD card. (source) - Configure the wireless network by dropping the
wpa_supplicant.conf
file into the boot partition of the SD card. (source) - Unmount SD card from computer, and boot Raspberry Pi.
Initial Configuration #
- SSH into
raspberrypi
, username: pi password: raspberry - Run
sudo raspi-config
- Run Update to update to the latest
raspi-config
tool. - Set System Options, including password, hostname, and auto-login.
- Set Display Options, including screen blanking.
- Set Performance Options, including Fan, and GPU Memory (16).
- Set Localization Options.
- Set Advanced Options, including Expand File System.
- Exit & reboot.
- Run Update to update to the latest
- 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.
-
Disable CEC commands via HDMI. (source)
echo "hdmi_ignore_cec=1" | sudo tee -a /boot/config.txt
-
Disable CEC active source message being sent during bootup.
echo "hdmi_ignore_cec_init=1" | sudo tee -a /boot/config.txt
Edit dotfiles #
- Create
.bash_prompt
- Add
source .bash_prompt
to bottom of.bashrc
Harden security on system #
Note: If you switch username, you’ll need to edit the dotfiles again.
Enable SSH access via key #
-
If you haven’t already, create an SSH key on the remote computer with:
ssh-keygen
-
From the remote computer, copy key to account on the Pi:
ssh-copy-id pi@HOSTNAME
-
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 #
sudo apt -y update && sudo apt -y full-upgrade
Install additional packages #
sudo apt -y install git git-core
sudo apt -y install lynx netatalk libssl-dev sshfs wiringpi
sudo apt -y install alsa-utils mpg321 mplayer
sudo apt -y install bluetooth bluez libbluetooth-dev libudev-dev
sudo apt -y install libavahi-compat-libdnssd-dev libcap2-bin libtool-bin
- (optional)
sudo apt -y install python-setuptools python-dev python-rpi.gpio
- (optional)
sudo apt -y install android-tools-adb
Install Node via NVM #
-
Install
nvm
-
Add NVM to path:
source ./.bashrc
-
Install a current version of Node:
nvm install 14
-
(optional) Install forever:
npm install -g forever