Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Use Your Raspberry Pi As A Headless System Without A Monitor

TwitterFacebookRedditLinkedInHacker News

I have a few Raspberry Pi computers all doing different things around my home. With the exception of my RetroPie, which I’ll talk about in a different article, they were all configured and running as a headless system. So what exactly is a headless system?

Headless Systems via IoT Agenda:

A headless system is a computer that operates without a monitor, graphical user interface (GUI) or peripheral devices, such as keyboard and mouse.

I use an iMac and my TV has all HDMI ports in use making it a hassle to switch them around. This means I needed to configure and use my Raspberry Pi in a different manner.

We’re going to take a look at installing and using Raspbian Linux on a Raspberry Pi without directly using a keyboard, mouse, and monitor. I am not a Windows user, so everything I’m going to demonstrate is using a Mac or Linux machine. A wild guess says that if you’re messing around with a Raspberry Pi, you’ve already got one of these Unix type operating systems.

This guide will be broken into the following sections:

  1. Downloading and installing Raspbian to an SD or micro SD card
  2. Discovering the Raspberry Pi on the network
  3. Enabling WiFi and removing one of our wires

The goal here isn’t to come up with a cool project idea. It is just to get up and rolling without a monitor. A classic use case is maybe you are creating network storage or doing something that will never need a monitor.

Downloading and Installing Raspbian to an SD or Micro SD Card

We’re going to use Raspbian for this example, but this step should be consistent for any flavor of Linux that supports the Raspberry Pi. Head over to the official Raspberry Pi website and get the latest build. I’m going to be using Raspbian Jessie, but the Lite version might make sense as well.

After you’ve downloaded it you may end up with a zip, img, or tar.gz file. What you want is the img file, so if you have anything else, you probably need to extract it. My img file was downloaded to my desktop for reference in this guide.

Insert an SD card or micro SD card into your computer either directly or via a USB conversion tool. If you’re using a Mac you’ll want to run the following commands in a Terminal with care:

diskutil list

This will list all available drives on your computer. Might look something like this:

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh HD            121.0 GB   disk0s2
   3:                 Apple_Boot Boot OS X               134.2 MB   disk0s3
/dev/disk1 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *3.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:          Apple_CoreStorage Macintosh HD            3.0 TB     disk1s2
   3:                 Apple_Boot Recovery HD             650.1 MB   disk1s3

On Linux, you can get something similar by executing the following from a Terminal:

df -h

It is very important that you recognize the correct drive in the list, otherwise you risk wiping the wrong drive. This is not something that can be undone.

Once you recognize the correct drive, pay attention to its first identifier. For example disk1 and not disk1s1. When you’ve got it, execute the following on Mac:

diskutil unmountDisk /dev/disk1

If you’re using Linux you’ll want to execute the following instead:

umount /dev/disk1

Remember to swap out disk1 with whatever disk is yours. With this done we can start the copy process. Execute the following from your Terminal:

sudo dd bs=1m if=/Users/nraboy/Desktop/raspbian.img of=/dev/disk1

Remember my Raspbian image is on my desktop. Change the if to wherever your image file is. Also change disk1 to the appropriate disk. This command is the same for both Mac and Linux. It took around thirty (30) minutes for the command to finish on my computer.

UPDATE 02/03/2017: As pointed out by some readers, the Raspberry Pi Foundation is disabling SSH by default in Raspbian as a security precaution. More information on the subject can be found here. To enable SSH, create a file called ssh and save it to the boot directory of the mounted drive before ejecting it from your computer. The file can be blank, and it has no extensions.

Assuming it finished and you didn’t blow up your computer, eject the SD or micro SD card and plug it into your Raspberry Pi.

Discovering the Raspberry Pi on the Network

Now we need to know how to access the Raspberry Pi without using a monitor or television. This can be accomplished using your host Mac or Linux computer and the network.

With the Raspberry Pi connected to a power source and an ethernet cable, execute the following from your Mac Terminal:

ifconfig | grep broadcast

After the broadcast address has been pinged, you can view the neighbor cache using an arp call. From your Mac or Linux machine execute the following:

arp -a

You’ll probably see a bunch of results similar to this:

? (10.0.1.1) at 0:1b:63:f2:f7:f1 on en1 ifscope [ethernet]
? (10.0.1.9) at (incomplete) on en1 ifscope [ethernet]
? (10.0.1.14) at 74:81:14:a5:72:5b on en1 ifscope [ethernet]
? (10.0.1.35) at 9c:e6:35:11:21:5e on en1 ifscope [ethernet]
? (10.0.1.255) at (incomplete) on en1 ifscope [ethernet]
broadcasthost (255.255.255.255) at (incomplete) on en1 ifscope [ethernet]

Now I’m lucky that I don’t have many devices on my network. Unless you know the MAC address of your Raspberry Pi’s ethernet, you’ll probably have to do the guess and check method here. Pick the IP addresses one by one and try to SSH to them using your Terminal similar to the following:

ssh pi@10.0.1.57

Notice I used pi as the SSH username? This is the default username for Raspbian. When you’ve finally hit the right address, use password raspberry to complete the login.

Enabling WiFi and Removing One of Our Wires

I’m not a fan of network cables. It is 2016 and by now wireless internet is nearly as fast as wired. I’d rather my Raspberry Pi only use a power cable and nothing else. For reference, I’m using an Airlink 101 wireless USB dongle that I picked up on Amazon.

I’m going to assume you’re still connected to Raspbian through SSH. Your USB dongle should be connected. If you’re just connecting it now, you probably want to reboot your Raspberry Pi in case it doesn’t immediately register. When you’re convinced you’re good, execute the following through SSH:

sudo iwlist wlan0 scan

This will tell you all the available networks. We did this just to test that it is working because we probably already know the SSID of the network we want.

Using VI for Linux, execute the following over SSH:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

The file probably won’t be empty. Go to the bottom of the file. A shortcut for this can be done by hitting Shift + G. When you’re at the bottom, add the following new lines:

network={
    ssid="your_network_ssid_here"
    psk="your_wifi_password"
}

If you’re unsure how to use VI, when you’re at the bottom of the file press the o key on the keyboard, type the stuff in, then press esc followed by :wq which means write and quit. You don’t have to use VI, you can use Nano if you want instead. Or technically you can use anything you want.

When you’ve done this, power down the Raspberry Pi by executing the following over SSH:

sudo shutdown -h now

After a minute when you’re sure it shut down, remove the ethernet cable and power the system back up. You should be good to go. Discover the Raspberry Pi on your network again using the previous step, but this time it will be through WiFi.

Congratulations, you set your Raspberry Pi to work without ever connecting it to a monitor. Now you can SSH to it and use command line Linux without issues.

Conclusion

You’re now rocking a Raspberry Pi without a monitor! You installed Raspbian by flashing an SD card via a secondary computer and discovering the microcomputer over the network. By taking it a step further with WiFi, you now only need a single wire running from the device. With SSH you can create your own network storage or whatever else is in your imagination.

I’m personally using one of my headless units as an rsync server.

A video version of this article can be seen below.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.