Sunday, 30 July 2017

Set up a Raspberry Pi without a display or keyboard

In many cases,  we want the solution to implement on our Raspberry Pi. It does not require physical access to the Pi, such as setting up a web server or a Minecraft server. It may happen that we do not have the necessary equipment (screen, keyboard, mouse) to control the Raspberry. So you'll be delighted to know that to put a Raspbian system in place. We don't need a screen or keyboard. And your computer can do the job.

Circuit Basics


There is a solution for setting up a Raspbian minimum on the Raspberry Pi, without a screen and without a keyboard, so that it can start and connect to Wi-Fi to your Internet network.

Elements required to set up Pi


In order to make a Raspbian installation on the Raspberry Pi, you'll need all the essential elements( i.e a Raspberry Pi 3b ). Its power supply and a MicroSD card (8GB is sufficient).

You will also need to retrieve the latest version of Raspbian, which can be download. We recommend the Lite version because we do not need the GUI. No need to take Chocapic pause, Raspbian Lite is relatively lightweight and downloads pretty fast. Once the image is recovered and decompressed, you will have to install it on the SD card, for that we made a detailed article ( here for Windows and there for Linux / Mac ).

Configure the MicroSD card


Now that Raspbian is installed on the SD card, we will be able to configure and modify some files so that the Raspberry Pi can run without a screen and without a keyboard. To do this, we will start by activating SSH on the Raspberry Pi. Remember, the rest of the tutorial is on your pc and not on the Raspberry Pi.

Enable SSH connection


Indeed since the attack that targeted the connected objects in November 2016, the Foundation Raspberry Pi decided not to activate the SSH connections by default. But in order not to block people opting for an installation without screen and without keyboard, headless therefore, the Foundation has put in place a simple and fast solution to activate the SSH. You simply create a file named ssh in the Boot partition (the file does not expect any extension).

When the Pi is first started, it checks to see if the file exists and activates the SSH accordingly.

Connect the Raspberry Pi to your Wi-Fi box


The SSH connection is now possible but there is still a step to make the Raspberry usable remotely, without keyboard or screen. Of course, I'm talking about making the connection to the internet, which is paramount to using the Pi remotely.

First, if you want to connect the Raspberry Pi via Ethernet, you can go directly to the next section because no configuration is required.

Here we need a Raspberry Pi 3b or a Raspberry Pi Zero W but the solution remains the same with other models (Pi 1B, 2B, Zero).

In order to configure the Wi-Fi connection when the Pi is started, we will edit the wpa_supplicant.conf file located in the / etc / wpa_supplicant / folder .

The file contains the following:

Ctrl_interface = DIR = / var / run / wpa_supplicant GROUP = netdev
update_config = 1
country = GB
We will add the following lines via the block-note application (or any other text editor, such as SublimText, NotePad, etc.).

network = {
        SSID = "MaBoxInternet"
        psk = "ClefSecurite"
        key_mgmt = WPA-PSK
}
In the ssid line , you will replace MaBoxInternet with the name of your box, for example , Livebox-5678 . For the psk field , this corresponds to the security code of your box, so replace ClefSecurity with the key of your box. And finally the last line corresponds to the security type of your box, usually WPA.

If you would like more information about Wi-Fi, we have made an article about this topic that you can find by following this link .

Set up a static ip for your Raspberry Pi
In order to know the ip that the Raspberry Pi will take, we will give it a static ip. For this we will modify the file dhcpd.conf located in the / etc / folder .

To modify the file, use the same software as to configure the Wi-Fi.

Once in the file, go to the last line and add the following content

Interface eth0
Static ip_address = 192.168.1.10 / 24
Static routers = 192.168.1.1
Static domain_name_servers = 192.168.1.1

Interface wlan0
Static ip_address = 192.168.0.10 / 24
Static routers = 192.168.1.1
Static domain_name_servers = 192.168.1.1

Let's take a look at all this, here interface eth0 corresponds to a connection of wired type and interface wlan0 to a Wi-fi connection . So you have to choose the one that corresponds to your setup.
Static ip_address is used to indicate the ip that your Raspberry Pi will have once started. Generally the ip is of type 192.168.1.x , replace the x with the value of your choice, be careful not to conflict with other devices .

As for static router and static domain_name_servers , this is usually the ip of your box, which is 192.168.1.1 .
You only have to save the file.

The SD card is now ready to be inserted into the Raspberry Pi and to start it without a screen and without a keyboard . All you have to do is login SSH to finalize the configuration of the Raspberry Pi (change of passwords, extend the SD card, etc). We invite you to consult our tutorial dedicated to the first startup of Raspbian .

5 comments:

  1. With raspbian you put a file called wpa_supplicant.conf in the same place as your ssh file and it gets copied across on boot. It just needs the contents network={... from your post.
    Then on boot from a Mac ssh pi@raspberrypi.local to connect

    ReplyDelete
  2. With pybakery (http://www.pibakery.org/) one can create a ready-to-go (ssh, connect to the wifi, etc.) installation directly on a sd-card. Insert the card, power up the pi and you're finished.

    ReplyDelete
  3. May i make russian translation?

    ReplyDelete
  4. No explanation about IP address config? Most "idiots" just copy-paste it without modifying and will be crying "doesn't work".
    Depending on your network configuration and which interface you want to use, you must match your network subnets especially when you're using mask /24 (255.255.255.0 - windows users). Based on your config, e.g.:
    If you have at home your network in subnet 192.168.0.0/24 then you'll be able to access your Pi only via wifi interface. If you plug a ethernet cable in it won't work: because your subnet don't match and no internet on Pi won't work either (gateway is in different subnet).
    And, so, if you have your home network in subnet 192.168.1.0/24 then you only be able access your Pi via ethernet cable - wifi will connect but won't work because subnets differ .
    The best is to setup at your router to assign to your Pi always the same IP address (for each interface), one note: you have to set for each interface MAC address different IP because if you Pi connect via WiFi and cable then you will have and address conflict (e.g.: for LAN: 192.168.1.10 , for WiFi: 192.168.1.11 - assuming that your router network subnet is 192.168.1.0 ).

    ReplyDelete