Pure headless Raspberry Pi setup from scratch

This guide assumes there is no Internet, no Wifi, no router, no display, no keyboard. All you need is:

  1. Download .zip of latest Raspbian .img file
  2. a Raspberry Pi and another Linux computer (could be a second Pi already running).
  3. a plain (or crossover) Ethernet cable–no router/switch required

1. Prepare laptop

We are going to use link-local networking, where the IP address will be in the 169.254.*.* range, no DHCP server needed. Here we assume NetworkManager on your laptop.

  1. create a new Ethernet connection, name it “link local” for convenience.
  2. under this new connection’s IPv4 settings, choose “link-local only”.

Note you may need to manually select this network profile when you plug the Pi into your laptop.

2. prepare SD card

  1. find SD card: before and after inserting it into the laptop:
    lsblk
    
  2. Example assumes the SD card is at /dev/mmcblk0. Be sure you have the right device! Burn the .img to the SD card (permanently erasing previous files on the SD card):
    unzip -p *raspbian-stretch*.zip | sudo dd of=/dev/mmcblk0 bs=1M
    

    This takes a few minutes and there’s no progress indicator. You can use iotop to watch how fast it’s writing.

  3. when writing appears done, type
    sync
    

    to be sure it’s done writing.

  4. Unmount/eject, remove and reinsert the SD card.
  5. In the SD card boot partition enable SSH on the headless Pi for first boot by
    touch ssh
    

    which creates a blank file named ssh. N.B.: this is NOT the boot directory in the 4 GB main partition of the SD card, this is a separate < 100 MB partition named boot. It has other important files like config.txt in it.

  6. Headless WiFi is enabled by editing from your laptop on the SD card the file /etc/wpa_supplicant/wpa_supplicant.conf and adding lines like
    network={
        ssid="my cool wifi router"
        psk="my wifi password"
    }
    

    Optionally, prioritize Wifi networks by the priority field, which can be a positive or negative integer.

    • default priority is 0.
    • equal priority Wifi then compared based on signal strength, security, etc.
  7. “eject” or unmount the SD card before removal, to avoid corrupting the SD card file system.

3. first boot headless Pi

  1. Insert the SD card into the Pi and boot.
  2. After about one minute, on your laptop plugged directly to the Pi via Ethernet:

    default password is raspberry

  3. logged into the Pi, change the default password to something else with
    passwd
    
  4. set unique hostname: raspi-config. If chose mypi then after Pi reboot:
  5. set locale to be UTF-8. Assuming you wish to have the United States locale, uncheck the default GB and check en_US.UTF-8 UTF-8. When prompted for default locale, also selected en_US.UTF-8 UTF-8.
    • if you don’t pick a UTF8 locale, Python may give UnicodeDecodeError with UTF8, even when .py script already has # -*- coding: utf-8 -*-.
  6. Again assuming you’re using a United States keyboard, set keyboard layout in raspi-config to Generic 104 keyboard, United States layout to avoid not being able to type symbols properly.
  7. Reboot, particularly to make the locale settings take effect.

Just a simple network switch connecting Raspberry Pis, PCs and other devices makes an internet-free, pure link-local “off the grid” network. Of course, you can also put the Pis on a wired or wireless network connected to the Internet if desired. The .local address functionality will NOT work over the Internet, but only on the LAN segment your device is on.

SSH server

Without further configuration, SSH servers listen on all interfaces. Normally this is fine.

If you want only specific interface(s) to have the SSH server listen, you will need to research ListenAddress of /etc/ssh/sshd_config and/or IPTables.

Leave a Comment