Raspberry Pi Headless Setup (No Monitor, Keyboard, Mouse)

I recently purchased a Raspberry Pi Starter Kit from Amazon. Its a great little PC, albeit a little sluggish. Here is what I had to do to get the Raspberry Pi setup without a keyboard, mouse, or display output – the only thing I had connected was the Power Adapter and an Ethernet cable.

The reason I had to do this was because I did not have access to a display with HDMI in at the time I received my Raspberry Pi.

The intent of this page is to get you to a point where you:

  • Have an RPi that is fully functional
  • Can easily identify your RPi on the network
  • Can SSH into your RPi
  • Can VNC into your RPi

What I ended up with by following these instructions, was a headless, WiFi-connected Raspberry Pi running Raspbian Jessie.

Prerequisites and Assumptions

Before we begin, there are a few pre-requisites that we must address.

  • The network you are connected to must hand out DHCP addresses
  • You need to be familiar with SSH
  • You have a MicroSD to SD Card Adapter
  • You are on a Mac — PC Instructions will be coming soon, however these instructions were created with the idea that the person who is setting up the RPi has access to a Mac. The idea is exactly the same, however – you need to somehow get the Raspbian image onto the MicroSD card.

General Information

NOOBS

NOOBS is an easy, guided way of setting up your Raspberry Pi. If you boot your RPi off a NOOBS MicroSD card, it will step you through choosing an operating system, and will automatically launch raspi-config  to configure your Raspberry Pi upon installation.

There are a couple of problems, however.

  1. The NOOBS interface requires keyboard input and monitor output so you can choose an operating system and customizations. This is bad if you don’t have a keyboard and/or monitor as it will just sit and wait for input.
  2. A lot of times, pre-loaded NOOBS MicroSD cards ship with out-of-date Linux Distributions on them.

Thus, if we create a bootable MicroSD card with Raspbian and not NOOBS it will address both of the above two points.

Step 1 – Download PiFiller

Step 2 – Download Raspbian

Step 3 – Create Bootable Image on MicroSD

You cannot simply copy the .img to the Micro SD and boot. You need to use a utility such as dd or PiFiller to do the job.

  • Remove your SD Card from your Mac if you have it in
  • Launch PiFiller
  • Point it to the .img you downloaded
  • When prompted, insert your SD Card

Important! Do not insert your SD Card before Pi Filler is prompting “looking for your sd card”, doing so will result in Pi Filler failing to find your card. Simply wait until the dialog box comes up and then insert your card.

  • Wait about 30 minutes until the process is complete

Step 4 – Hook Up RPi to Ethernet

  • Plug the RPi into an ethernet port that is on a network where DHCP is active.

Step 5 – Boot RPi

  • Plug the power adapter into the Raspberry Pi – it will boot automatically.

Step 6 – Find IP Address using PiFinder

  • Grab the PiFinder from Ivan X here http://ivanx.com/raspberrypi/files/PiFinder.zip [mirror]
  • Launch it — it will scan the network for your Raspberry Pi and give you the IP Address. It does this by pinging all IP Addresses in your network and grepping the arp tables for the Mac Address containing B8:27:EB.

If PiFinder fails, and you have access to it, you could pay your DHCP or DNS Server(s) a visit and try to decipher which address belongs to your Pi. This is easier done in small home networks.

Step 7 – SSH into RPI

  • Fortunately, SSH is Enabled by default on the Jessie release of Raspbian. Other flavors of Linux, and even previous generations of Raspbian SSH was not enabled by default.
  • The default username and password for the Raspberry Pi Raspbian Jessie is username: pi password: raspberry.
ssh -l pi your-raspberry-pi-ipaddress-here

Step 8 – Recreate SSH Keys and Change Raspberry Pi Password

sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
sudo service ssh restart
sudo -i
passwd pi
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@raspbmc:~#

From now on you can connect to your RPi over SSH with the password you just set.

Step 9 – raspi-config

Now its time to configure some of the features of the Raspbian OS. Fortunately theres a nice wizard for this

sudo raspi-config

Screen Shot 2015-11-27 at 10.08.47 PM

  • Update raspi-config (bottom option)
  • Choose “expand_rootfs”
  • Enable/Disable any other options you want like timezone, etc

Step 10 – Install and Set VNC Password

sudo apt-get install tightvncserver
vncpasswd

Step 11 – Set VNC to run at boot

Create a new file called vncboot in /etc/init.d.  Do this with your favorite editor (vim, vim, etc). This will hold the commands necessary to run vncserver on boot.

sudo vim /etc/init.d/vncboot

The contents of the file should be this

#!/bin/sh
# /etc/init.d/vncboot
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO
USER=pi
HOME=/home/pi
export USER HOME
case "$1" in
 start)
  echo "Starting VNC Server"
  #Insert your favoured settings for a VNC session
  su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
  ;;

stop)
  echo "Stopping VNC Server"
  /usr/bin/vncserver -kill :0
  ;;
*)

 echo "Usage: /etc/init.d/vncboot {start|stop}"
 exit 1
 ;;
esac
exit 0

Make the file executable

sudo chmod 775 vncboot

Tell Raspbian to run this on reboot

sudo update-rc.d vncboot defaults

You can now connect to your Raspberry Pi using your favorite VNC Viewer, or by connecting to it via Go > Connect To Server > vnc://ipaddresshere from your Mac finder menu.

Step 11 – Configure Wireless

Now that you can VNC in, configuring your wireless adapter so you don’t have to be tethered by the pesky Ethernet cable is simple.

  • SSH into your Raspberry Pi
  • Add the following lines to /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Now, edit (or create if it doesn’t exist) your /etc/wpa_supplicant/wpa_supplicant.conf file. Make sure the configuration settings match up (eg: if you don’t use WPA-PSK, change the relevant line to WPA-EAP, etc).

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={
ssid="YOURSSID"
psk="YOURPASSWORD"

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN
}

Congratulations, you now have a working Raspberry Pi. You know how to find it, SSH into it, and have configured it to allow for VNC access.

Other Posts

You may also be interested in some of my other posts:

Have fun and hope this helps.

 

6 Comments

  1. Definitely grateful for this write-up. Thanks! One note – shouldn’t the code in step 10 be “apt-get” and not “adpt-get”?

  2. The code is stylized by WordPress. If you cut-and-paste you have to change the ” to standard ones and the en-dash (–) between su and pi to a standard hyphen (-), and the multiplication cross in the geometry resolution to a regular x.
    The top line should also be
    #!/bin/sh

    1. Thanks. I made the #!/bin/sh change and I installed a more code-friendly plugin that doesn’t have problems stylizing. Now to change all the codeblocks around here.

Leave a Comment

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