From eBower Wiki
Jump to: navigation, search

The initial setup for a Raspberry Pi appliance is pretty simple - especially if you've got a Linux distribution on your desktop.

Prepping the SD Card

First you'll want to download the latest Raspbian Image. You can go with one of the other options as well, but I've found that Raspbian seems to have the best support and gives me the familiar tools such as apt-get.

You'll need to burn it to an SD card[1]. Under Linux this is easy:

dd bs=4M if=[image_iamge] of=/dev/sd[x]

Under Windows you'll need to download the Win32 Disk Imager and run it.

By default, this should be all you need to do from your desktop.

Finding Your Pi

If you're hooking up your Pi to a monitor and keyboard you probably need a better role model (OK, maybe there are some use cases where you don't need to be headless but I haven't run into any...). So, how do you install and configure a Pi if you don't know where it is? Well, first I assume you've got a model B with an Ethernet port. The benefit here is that you don't need to configure anything (unless you use 802.1x), you just plug and play. I've created a script which will scan your network for Pi MAC addresses[2] and then ssh into it for you if it finds one:

# If you don't want to use eth0, specify the interface you want
if [ "$1" != "" ]; then
# We need nmap for this
if [ "$(whereis nmap | awk '{print $2}')" == "" ]; then
  echo Please install nmap:
  echo sudo apt-get install nmap
  exit 1
echo Scanning $iface
# The pi starts up in IPv4 mode :(
if_data=$(ifconfig $iface | grep -w inet)
# Grab the IP and subnet
ip_addr=$(echo $if_data | awk '{print $2}' | awk -F\: '{print $2}')
subnet=$(echo $if_data | awk '{print $4}' | awk -F\: '{print $2}')
# Do a bitwise and of the IP and the subnet to get the network address.
network=$(echo ${ip_addr}.${subnet} | awk -F\. '{print and($1,$5)"."and($2,$6)"."and($3,$7)"."and($4,$8)}')
# Convert the subnet to / notation by:
# * Creating an array of what each possible value is
# * Traversing the four octets and looking up the array value
# * Adding them all together.
mask=$(echo $subnet | awk -v netmask=$subnet '
    bits = 8
    for(x = 255; x >=0; x -= 2^i++)
        cidr[x] = bits--
    split(netmask, arr, "[.]")
    for(i = 1; i <= 4;i++)
        total += cidr[arr[i]]
    print total 
# First we need to seed the arp table by pinging all addresses in the network
nmap -e $iface -sn $network/$mask > /dev/null
# Grep for the Pi MAC address prefix and grab the results.
pip_address=$(arp -a | grep b8:27:eb | awk '{print $2}' | tr -dc '0-9.\n') 
echo "$pip_address"
if [ $(echo "$pip_address" | wc -l) != 1 ]; then
  if [ "$pip_address" == "" ]; then
    echo "Unable to find your Pi, check the power and Ethernet then try again!"
    echo "Multiple Raspberry Pis found:"
    echo "$pip_address"
    echo "You can login to your pi with ssh -o PubKeyAuthentication=no pi@[ip]"
  if [ "$pip_address" == "" ]; then
    echo "Unable to find your Pi, check the power and Ethernet then try again!"
    echo Login with the password \'raspberry\'
    ssh -o PubKeyAuthentication=no pi@$pip_address

Initial Config

The first thing you'll want to do is run:

sudo raspi-config

This will let you resize your partition to the full SD card and a few other things.

Now we can do some updates:

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get install vim && sudo apt-get autoremove

Enable IPv6

You'll also want to run the following and add ipv6 to the end of the file (come on, Raspbian people, it's not 2011 any more!):

sudo vi /etc/modules

Disable Password Logins

You'll also want to secure the system a bit:

mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -f [filename]
cp [filename].pub authorized_keys
chmod 600 authorized_keys

Now on your desktop, run the following:

scp -o pubkeyauthentication=no pi@[ip]:.ssh/[filename] ~/.ssh/
scp -o pubkeyauthentication=no pi@[ip]:.ssh/[filename].pub ~/.ssh/
vi ~/.ssh/config

Now add the following entry:

Host [host]
  IdentityFile ~/.ssh/[filename]
  User pi
  Hostname [ipaddress]
  Port 22

If you can run ssh [host] and login to your Pi, you can proceed.

sudo vi /etc/ssh/sshd_config

Now find the PasswordAuthentication line, uncomment it, and set it to no.


  1. Installing Operating System Images - Raspberry Pi Documentation
  2. Raspberry Pi MAC Addresses