For many applications it is not always necessary for a RaspberryPi to have a keyboard, mouse and screen. Many tasks can also be received and executed by the RaspberryPi via the network. In addition, this can save costs for peripherals. This setup is then called “headless”. In order for this headless pie to be addressed, it must be located in a network. By default, the Raspi does not know any networks when it is first started and these must first be entered. If you want to shorten the procedure and start headless directly, you have to configure the boot files first.
Prepare SD card
Download Raspbian or a similar operating system for your RaspberryPi and install it on a free SD card of your choice. The minimum size of the SD card varies, check the provider’s site. However, 8GB or larger is best, as you may also want to install one or two other programs later.
Configuring WLan correctly at boot time
The file “/boot/wpa_supplicant.conf” must be changed to:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country="your_ISO-3166-1_two-letter_country_code"
network={
ssid=""your_SSID""
psk=""your_PSK""
key_mgmt=WPA-PSK
}
Where <<your_SSID>> is the wifi name and <<your_PSK>> is the wifi password. The ISO country code “your_ISO-3166-1_two-letter_country_code” must also be exchanged with the corresponding code (e.g. “DE” for Germany).
If the wifi password is not to be stored as blank text, the “wpa_passphrase” function can be used to store the password as a hash.
wpa_passphrase "your_SSID"
The terminal will then ask for the password and generate a hexadecimal hash from it, which can be passed in the “wpa_supplicant.conf”.
Multiple networks
A RaspberryPi is small and portable. If it needs to access different networks in different locations, each wifi network can simply be included in the “/wpa_supplicant.conf”. At start-up, the .conf file is searched and connected to the first available wifi. For another workstation it could look like this:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country="your_ISO-3166-1_two-letter_country_code"
network={
ssid=""your_SSID""
psk=""your_PSK""
key_mgmt=WPA-PSK
}
network={
ssid="office-wlan
scan_ssid=1
key_mgmt=WPA-EAP
eap=PEAP
identity="WORK_USERNAME"
password="WORK_PASSWORD"
phase1="peaplabel=0"
phase2="auth=MSCHAPV2"
id_str="SOME_DESCRIPTIVE_NAME"
}
Disable DHCP
For multiple RaspberryPis, it may be useful to call them using your hostname instead of an IP address assigned by the router via DHCP. To do this, we change the file “/etc/network/interfaces”:
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
post-up ifdown eth0
iface default inet dhcp
Please note that the hostnames of several Pis must not be identical. You can change the hostname via “/etc/hostname”.
Enable SSH at first boot
By default, the Secure Shell Host is disabled when booting the RaspberryPi (for security reasons). To start SSH operation from the beginning, the folder “/ssh” is created in the folder “/boot” on the SD card. It doesn’t matter if there is anything in this folder or not, Raspbian only looks for the folder during the boot-up process and then activates SSH.
Alternate: Use the Raspberry Imager Tool
We will start at your Computer. Insert the SD card into your computer.
Writing the Image to SD card
Update your Distribution and install the RPi imager.
sudo apt update
sudo apt upgrade
sudo apt install rpi-imager #tool to download and install images onto SD card
rpi-imager
In this Series we use the RaspberryPi OS without desktop environment. Now we can configure the Image to start at best conditions.
Enable SSH
To enable SSH directly on the SD card add a new file named ssh, with no extension, to the
If you have added an empty file ssh to the boot sector of your SD card (touch /boot/ssh), the Pi will start with SSH enabled. After that we can connect from your laptop with: ssh pi@raspberrypi.local (or ssh pi@<IPADRESS> when the ip adress in known).
Booting up your Pi
Insert the SD card into your RapsberryPi, connect it to your router and power it on. After the startup we can connect via SSH
ssh pi@raspberrypi.local and log in (default pw is “raspberry”).
Normally your raspberry can be found in the same network with raspberrypi.local. If not check your routers ip table to find your RPis IP and connect @<localip>
If you don’t have a wire-connection you can use your Wifi.
Start using the RPi with raspi-config to configure all settings.
💬 Comments
Comments are not enabled for this article yet.