In this post we are going to set up a Raspberry Pi without a monitor or keyboard or mouse. This is what we call a “Headless” configuration and is very useful when we want to dedicate our device to tasks such as web server, home automation, or robotics, among many other examples.
The most common solution is to do the first boot connected to a monitor and keyboard, configure it to our liking, and finally take it to its final application. In this post we will see that we can skip this step and perform a completely Headless setup from the first boot.
In general, in the Headless configuration we seek to enable SSH and configure connectivity. With this we can access the Raspberry Pi via SSH and make the rest of the configurations. Optionally, we can enable the VNC and access by remote desktop.
Fortunately, Raspbian has a couple of “tricks” that allow Headless configuration from the first boot. Let’s see the setup process starting from an empty SD card.
As we know, as a security measure SSH is disabled by default in the Raspbian installation. However, we can enable it simply by creating a file called ‘ssh’, without extension, inside the SD card we prepared in the previous step.
If we are going to connect the Raspberry Pi via WiFi, we must configure the ‘wpa_supplicant.conf’ file as we saw in the post configure Wifi on Raspberry Pi by GUI or Terminal.
Similar to SSH, we can add our WiFi configuration simply by creating the ‘wpa_supplicant.conf’ file on the SD card we prepared. When Raspbian starts up, it will take the WiFi configuration file from the SD card.
Remember that the format of ‘wpa_supplicant.conf’ is as follows:
Find the Raspberry Pi address
We get to the part that could give us some trouble. At this point when we turn on the Raspberry Pi, it will be connected to the local network, and SSH will be enabled. But to connect we need to know the address of the Raspberry Pi in our network.
Unfortunately, for now, Raspberry Pi does not have a function to configure the address by adding a file to the SD card, as we did with SSH and WiFi. So we will have to find the dynamic IP that has been assigned to the Raspberry Pi on our network.
For that, we have different options:
- Try to connect using ‘raspberrypi.local’ as the address.
- Use an IP scanner program on the network such as, for example, Nirsoft Wireless Network Watcher (Windows) or Fing (Android).
- Find the IP of the device by accessing the Router settings.
In most cases any of these options will work for us. But depending on how the network is (size, security, etc.) some (or all) we may not be able to use them.
If you have access to a computer with Linux or Mac, another option is to mount the SD card and directly configure a static IP as we saw in this post.
If none of the above works, you can try putting your device in ‘Wifi Sharing’ mode and connect the Raspberry Pi to it. Configure a static IP and finally connect it to the final network.
Configure the rest of the options
Once we have SSH access to the Raspberry Pi we can configure the rest of the options as usual using ‘rasp-config’, as we saw in the post how to configure Raspberry Pi with GUI or command console. For example, you can activate VNC and access by remote desktop.
As you can see, the Headless configuration is a simple process that only takes a few minutes, and saves us the headache of having to connect the Raspberry Pi to a monitor and keyboard only for a first boot.