Setup a Raspberry Pi with No Keyboard or Monitor

So I bought myself a Raspberry Pi! After picking up the device I stumbled onto my first challenge pretty quickly... how do I set this thing up without access to a keyboard or monitor? Fortunately, a headless setup is relatively painless. With a laptop and SD card reader, you can be up and running in no time with remote access to the command line via SSH.

raspberry_pi.JPG

1. Requirements

Hardware

  • Raspberry Pi (my model is specifically the Raspberry Pi 3 Model B v1.2)
  • 16GB micro SD card (Class 10)
  • A laptop with an SD card reader.

Software

  • Rasbian OS (I have used Raspbian Stretch Lite, November 2017)

2. Setup the SD Card

1. Perform a FAT32 format on the SD card.

  • On the Mac: Disk Utility > Erase > MS-DOS (FAT).
  • If you run into issues, use the SD Memory Card Formatter.
  • You will need to give your disk a name, I've called mine RASPBERRY.

2. Once formatted, find the device name by opening Terminal and typing: df -h

01_file_system_disk_usage.png

3. Unmount the disk.

  • On the Mac: Eject from Disk Utility or Finder.
  • Via Terminal: sudo unmount /dev/disk3s1 (Note: Your disk name may vary).
02_unmount.png

4. Change into the directory that contains the Raspbian image file (e.g. cd Downloads).

5. Type the following command to uncompress the image and write it to your SD card.

  • sudo dd bs=1m if=YOUR_IMAGE_NAME.img of=YOUR_DISK
  • e.g. sudo dd bs=1m if=2017-11-29-raspbian-stretch-lite.img of=/dev/rdisk3

You will notice that I have used /dev/rdisk3 rather than /dev/disk3s1, this is in order to reference the raw device. If your disk name was /dev/disk2s1, you would use /dev/rdisk2.

6. Once complete, the boot partition will automatically mount.

3. Enable Wireless Networking

1. Change directories by typing: cd /Volumes/boot

2. Create a file by typing: nano wpa_supplicant.conf

3. Type the following followed by these key presses to save and exit: Ctrl+X, Y, Enter.

country=YOUR_COUNTRY_CODE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOUR_WIFI_SSID"
    psk="YOUR_WIFI_PASSWORD"
    key_mgmt=WPA-PSK
}
03_wifi.png

4. Enable SSH

Simply create an ssh file with no extension in the /Volumes/boot directory by typing: touch ssh

At this point your SD card is ready to go, unmount the disk and insert it into your Raspberry Pi.

5. Power Up

1. Turn on the Raspberry Pi by plugging in the micro USB power supply.

2. After you have given the device some time to boot up and connect to the Wi-Fi, find the Raspberry Pi's local IP address. There are multiple ways you can do this, I've personally used LanScan but you could also use nmap or check out your router's list of connected devices.

6. Remote Access via SSH

1. Open Terminal and type: ssh pi@local_ip_address (e.g. ssh pi@192.168.0.23)

2. You should see a prompt "The authenticity of host ‘192.168.0.23 (192.168.0.23)’ can’t be established…. Are you sure you want to continue connecting (yes/no)?", type: yes

3. Enter the default password: raspberry

7. Safely Shutdown

While you can simply unplug the micro USB cable, to shutdown safely type: sudo poweroff. Once the green light stops blinking you can remove the power cable.

That's it, you are ready to go.