Skip to content

Instantly share code, notes, and snippets.

@i3games i3games/headless-pi.md
Last active May 1, 2019

Embed
What would you like to do?
How to set up your Raspberry Pi including WiFi without monitor and keyboard from a Mac.

Set up Your Raspberry Pi Headless in 10 Easy 🤔 Steps

Goal

You want to set up your Raspberry Pi without monitor and keyboard. This is sometimes called "headless". Don't worry, you'll keep your head if you follow these step-by-step instructions (however, see license and disclaimer below). We will install the Raspbian operating system and configure the Pi WiFi from a Terminal session on a Mac.

Prerequisites / Assumptions

You have:

  • A Mac with a SD card reader (either built in or an USB device).
  • A Raspberry Pi 3 B (A Pi 2 B with a compatible WiFi dongle works as well).
  • A new micro SD card with at least 8 GB and a normal size SD card adapter.
  • A micro USB power adapter that provides 5V, 2A (check the label).
  • An Ethernet cable (this is like WiFi but over a cable. Ask your parents/grandparents if in doubt).
  • Your WiFi password.
  • Physical access to your WiFi router.
  • Access to your WiFi router setup/admin interface. You will need the password for this. This is different from your WiFi password. Check if it is written on the device or came with the material you got with the router.

Step 1: Download Raspbian

Go to https://www.raspberrypi.org/downloads/raspbian/ and download the "Raspbian [XYZ] with Pixel" ZIP file.

Step 2: Put Raspbian on your SD card

Go to https://etcher.io/, download and install the program. Start it and select the ZIP file, the drive with the SD card and start the copy ("Flash!"). Grab a coffee.

Step 3: Prepare Raspbian for ssh

When etcher is finished, reinsert the card into the SD card reader. The volume with the SD card will show up in Finder. Its name is boot and there are a couple of files on it. Look for files with the extension ".txt" (if you don't see any extensions please open Finder -> Preferences -> Advanced and check Show all filename extensions). Right click on one of them - which one doesn't matter - and choose "Duplicate". Then right click on the copy that you just created and rename this file to ssh. This is: ssh without any extension. Your Mac will ask if you are sure to drop the extension. Yes, you are.

Step 4: Start the Raspberry Pi

Eject the boot volume / SD card in Finder. Remove the micro SD card from the adapter and put it in the Pi. Find a free power socket near your WiFi router. Connect the Pi to the power source through the micro USB power adapter. The LEDs on the Pi should start blinking. Connect the Pi to the router through the Ethernet cable.

Step 5: Get into your router to find the Raspberry's IP Address

Head back to your Mac. Hold the "alt/option" key and click on the WiFi icon on the right side of the title bar. There you see some information about the WiFi you are on. Look for "Router:" followed by an IP address. Enter this IP address into your web browser. Your router's setup/admin interface should show up. Enter the password for it.

Now there might be many options and settings. Just take your time and look for an entry that lists the currently connected devices. The Raspberry Pi should be among them. Write down the IP address displayed for the Pi. If it is not, retrace the steps above and make sure you double check everything. Does the SD card sit firmly in the Pi? Is the Pi connected to the router (maybe try another Ethernet port)? Restarting the Pi by removing the power connection is another idea. Important: Before you do that you also have to do Step 3 (putting the SD card in the mac, creating the file named ssh, ...) and/or Step 5 (find the IP address of the Pi) again.

Keep the router page open for later.

Step 6: Connect to the Pi

Open a Terminal on the Mac and enter

ssh pi@xxx.xxx.xxx.xxx

where xxx.xxx.xxx.xxx stands for the IP address you got in Step 5. Your Pi should answer with some mumblejumble you have to confirm with yes. Then provide raspberry as a password. If it gives other hostile answers, it is likely that you need to do Step 3 again.

If everything works so far, cool.

Step 7: Update Raspbian

In the terminal, enter

sudo apt-get update

and after that

sudo apt-get dist-upgrade

You need to confirm the upgrade. If you are asked for a password, raspberry is the answer. This may take a few minutes. Time for a walk, some Yoga or a snack. Almost done.

Step 8: Prepare the WiFi

In the terminal, enter

wpa_passphrase "SSID" "WIFIPASSWORD"

where SSID is the name and WIFIPASSWORD the password for your WiFi.

It will spit out a structure that looks like this:

network={
  ssid="testing"
  #psk="testingPassword"
  psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
}

This shows the name of your WiFi, the password for your WiFi and a long sequence of letters and numbers. Select the whole thing with your mouse and Right click, then choose "Copy".

In the terminal, enter

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

It will open a file. Navigate to the end of it with the cursor keys, Right click and "Paste". Now delete the line that starts with #psk=. That's the middle one. In the example above we now would have left:

network={
  ssid="testing"
  psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
}

Hold the control/ctrl key and press x. Confirm the question if it should save the buffer.

Finally go back to the Pi and remove the Ethernet cable. Disconnect the Pi from power and reconnect again. Wait a little.

Step 9: Connect to the Pi again

Refresh the router page from Step 5 in your web browser, and you hopefully see the Raspberry Pi again. If you don't, check Step 8 again. If you do, the Pi is now connected over WiFi. Write down its IP address. On your WiFi, this address should be the same in the future, but it is possible that the Pi gets assigned another one from the router. In that case you need to consult the router setup/admin page again.

Open a new Terminal and ssh to this address in the same way as you did before:

ssh pi@yyy.yyy.yyy.yyy

... (the password is still raspberry) and you should be in. Congrats. You are now running the Pi with WiFi and connect to it via ssh. 🙂

Step 10: Change your password on the Pi

At the moment everyone who is on the same network can take over your Raspberry Pi completely and do bad things with it 😔. So before you go on, you should change the password.

In the Terminal, enter passwd. You will be asked for the current password (raspberry) and then chose a new one that you should remember well.

Now you can start exploring your Pi. Lots of information is available on https://www.raspberrypi.org/.

Remarks

1: "Easy" is always relative.

2: The only reason for a Mac in the prerequisites is that I ran through these steps on a Mac. It should be very similar on other operating systems, but I didn't test it.

License / Disclaimer

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

Please check Section 5 of the linked license for a disclaimer of warranty for the information given here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.