Pure headless Raspberry Pi setup from scratch

This guide assumes there is no Internet, no Wifi, no router, no display, no keyboard, and nothing more than

  1. a .zip of the latest Raspbian .img file: previously downloaded by

     wget https://downloads.raspberrypi.org/raspbian_lite_latest
    
  2. a Raspberry Pi and another Linux computer (even 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. determine where the SD card is by before and after inserting it into the laptop using the command

     lsblk
    
  2. here we assume the SD card was 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) by

     unzip -p *raspbian-stretch-lite.zip | sudo dd of=/dev/mmcblk0 bs=4M
    

    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. in the BOOT partition enable SSH on the headless Pi for first boot by

     touch ssh
    

    which creates a blank file named ssh

  5. 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"
     }
    
  6. “eject” or unmount the SD card before pulling it from your laptop to avoid corrupting the file system.

3. first boot headless Pi

  1. Insert the SD card into the Pi and boot.
  2. After about one minute, try

    default password is raspberry

  3. logged into the Pi, change the default password to something else with

     passwd
    
  4. use raspi-config to set the hostname to something unique–let’s say you choose joespi then after reboot you will

Now you can use networks of Raspberry Pis, PCs and other devices with network switches for a pure link-local “off the grid” network, or put them on a wired or wireless network.

Pi SSH server listens on all interfaces

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