Headless Raspberry Pi configuration

Settings up a Raspberry Pi it’s easy when you have an HDMI display, a USB keyboard and mouse in oder to access the terminal or you favourite Desktop, but can be quite a challenge when you don’t have any of these or at least no keyboard.

Everything in this blog post should be done from you host computer, with you microSD card connected and mounted, assuming the microSD is mounted at /Volumes/boot.

cd /Volumes/boot
Raspberry Pi 4 with Hyperpixel 4.0 display

Enable SSH over LAN / WiFi

The SSH server is not enable by default as a user it’s expected that you access your Raspberry using a KVM. Not a Linux Kernel but a Keyboard, (VGA) Display and Mouse. This can be easily done by creating an empty file named ssh.

touch ssh

Preconfigured a WiFi network

If you are going to connect to Raspberry to your network using an Ethernet cable, you can skip this part. But if a WiFi network (even your mobile phone as a hotspot) it’s you only option, you can set your default WiFi network config in a file called wpa_supplicant.conf

sudo vi wpa_supplicant.conf
    ssid="<< your WiFi's SSID >>"
    psk="<< your WiFi's password >>"

Take into consideration that this configuration uses your password in plain-text! If you want to encrypt your password in this configuration file do the following:

wpa_passphrase "<< your WiFi's SSID >>" "<< your WiFi's password >>"

On a Linux distribution wpa_passphrase is installed, but on macOS or Windows not. the following Ruby script will use OpenSSL in order to create the content of the configuration file.

vi /tmp/raspi_wifi.rb
require 'openssl'
ssid = '<< your WiFi SSID >>'
psk  = 'ID >>" "<< your WiFi password >>'
puts 'country=AR'
puts 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev'
puts 'update_config=1'
puts ''
puts 'network={'
puts '  ssid="' + ssid + '"'
puts '  psk=' + OpenSSL::PKCS5.pbkdf2_hmac_sha1(psk, ssid, 4096, 32).unpack("H*").first
puts '  key_mgmt=WPA-PSK'
puts '}'

Then run the script and copy the output to /Volumes/boot/etc/wpa_supplicant/wpa_supplicant.conf

ruby /tmp/raspi_wifi.rb > /Volumes/boot/wpa_supplicant.conf

Accessing your Pi using SSH

Now when your Raspberry completes its boot process, you will be able to access your device using SSH even without knowing its IP address.

Raspberry exposes a host in your local domain, so the following command with let you know it IP address.

ping raspberrypi.local

The default Raspberry user and password are pi and raspberry, so the following command will establish a SSH connection

ssh pi@raspberry.local 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s