Headless raspberry pi – my first steps

raspberryThis post collects some information and my own experience about setting up a headless raspberry pi – this means there is no keyboard, monitor or mouse connected to the raspi. All the communication to the user is done via ethernet. In my case there’s also no graphical interface. There is nothing new in this article. It is a compilation of information found at different places over the internet. But as it took me some time to find it I thought it could be helpful to have it all in one place.

Starting with raspbian

The operating system of a raspi is on a SD card or micro SD card depending on which raspi you choose. The raspberry pi foundation publishes different images of the preinstalled operating system. So you only have to copy the image to your SD card, plug it into the raspi and then the raspi starts directly from the SD card. No further installation needed. 🙂 The raspberry pi foundation has detailled information on how to prepare the SD card here on a Linux machine.  This is what I did (mostly) – and failed. So here is one of the reasons I’m writing this post. The other possibility is to use a preinstalled SD card that contains NOOBS. This is not covered here.

I found an old 8GB micro SD card lying around – perfect for my pi B+. So I followed the instructions, copied the image to the SD card but the raspi didn’t do anything. It took me some time to find out that the card was faulty and data was corrupted.

Now here is what you do on a Linux computer to prepare your SD card:

  • Download the zip archive here. In my case it’s
  • In a terminal go to the directory where the zip file lies.
  • Now to check if your download is correct,
    type md5sum 2017-01-11-raspbian-jessie-lite.zip and compare the result with the md5 sum that is given on the download page.
  • Unzip it with unzip 2017-01-11-raspbian-jessie-lite.zip
  • Now find out the device name your computer gives to the SD card. Therefore type in the terminal: df -h before you insert the SD card. After you’ve inserted the SD card type df -h again. The newly appeared device is the SD card, e. g. /dev/sdd where /dev/sdd1 is the first partition on that device and /dev/sdd is the name of the whole card. If no new device appeared you probably see a new symbol on the desktop. Right-click it and mount it. Then you should see it in the df -h output.
  • The next step is to unmout the SD card from the filesystem. If your SD card is at /dev/sdd you type umount /dev/sdd1 If your SD card has several partitions as can be seen in the output of df -h then unmount all other partitions of the card, too.
  • Write the image to the SD card with:
    sudo dd bs=4M if=2017-01-11-raspbian-jessie-lite.img of=/dev/sdd and replace /dev/sdd with the name of your SD card!!! You can also become root and use dd without sudo. This is the same with all following commands. If the block size 4M doesn’t work try with 1M which will take longer. While dd writes to the card you will get no output. At the end there is an output that tells you what dd has done, You can also see the write speed of your SD card.
  • The next step is to do what I didn’t: Write back the content of the SD card and compare with the original file. Therefore you do:
    sudo dd bs=4M if=/dev/sdd of=from-sd-card.img
    If you are already root then type it without sudo. This creates a new file on your harddisk with what is read from the SD card. The dd command also shows you the read speed of your SD card. The file you get back is normally longer than the original file so truncate it to the right size. All following commands can be done without root priviledges:
    sudo truncate --reference 2017-01-11-raspbian-jessie-lite.img from-sd-card.img
    And then compare both files:
    sudo diff -s from-sd-card.img 2017-01-11-raspbian-jessie-lite.img
  • Before plugging out the SD card type sync in your terminal to have the write cache flushed. Then you can remove the card.

This is what you have to do to be sure that everything is ok on your SD card.

Setting up ssh for a headless raspi

In a standard configuration you connect your monitor, keyboard and mouse to the raspi, plug in the SD card and start. This will not work in headless operation because the only way to communicate is ssh but ssh is disabled by default for security reasons. So there’s no communication and thus no possibility to enable ssh 🙁

The solution to this is described here: Leave the SD card in your computer and open the boot partition of the SD card. After writing the image (above) the SD card has two partitions. On a desktop environment the new partitions show up by default and you can open the boot partition with your favourite file manager. Then create a new empty file with the name ssh. Unmount the SD card and you’re ready to go 🙂

Connecting to your raspi

Now it’s time to start: Plug the SD card into your raspi, connect the raspi to your local network (e. g. dsl router) with a standard ethernet cable and then connect 5V power. The raspi has DHCP enabled and gets its IP address from the router. To find out the IP address you can look in the device table of your router. E. g. when the IP address is then type in your terminal
ssh pi@
The @pi is important as you want to log in as the user pi which is the standard user. When you get asked for the password you’re almost done. The standard password is raspberry. Now you should see the debian login messages and the shell prompt of your raspi:
pi@raspberrypi:~ $
Now your ssh connection is up and running 🙂 Change the password with the passwd command to your individual password to prevent others being able to log in with the standard password.



2 thoughts on “Headless raspberry pi – my first steps

  1. RT Happe

    Useful writeup. One minor correction, though:
    Write the image to the SD card with:
    sudo dd bs=4M if=2017-01-11-raspbian-jessie-lite.ZIP should be IMG, i.e.
    sudo dd bs=4M if=2017-01-11-raspbian-jessie-lite.img of=/dev/sdd.


Leave a Reply

Your email address will not be published. Required fields are marked *

− 4 = 3