Ultimate Raspberry Pi Configuration Guide

404,906

1,701

52

About: Scott Kildall is an new media artist and researcher. He works at Autodesk, Pier 9 and is an artist-in-residence with the SETI Institute

Intro: Ultimate Raspberry Pi Configuration Guide

The Raspberry Pi is a great thing: it is real computer, it is cheap ($40), it can interface with electronics, talk to the web and has full HDMI support.

However it runs on Linux, which I have a love-hate relationship with. I love the idea of Linux, but when I start messing around the command line and downloading packages and installing things, I often get lost.

I've assembled bits and pieces from various online posts and guides into this Instructable, which is what I call the "Ultimate Raspberry Pi Configuration Guide".

What this Instructable does is to set up a wireless Raspberry Pi that allows you to:
  • ssh into from the Terminal window on the Mac (or equivalent on another machine).
  • run wirelessly with a static IP for each SD card.
  • automatically startup, no log in
  • set your the time zone
  • skip the GUI of the Raspberry Pi, which bogs things down and is unnecessary for most tasks
  • minimize any external monitor use, specifically never having to lug a monitor over to where the ethernet router lives
  • clone a "basic settings" SD card so that we can have as many base-level installations as we want.

Right now, I have 3 Raspberry Pis running in my closet, each with a different purpose: one runs 7 Twitterbots, one is a Git server and one is an experimentation device for electronics. I plan to add more. 

I wrote this Instructable for someone who has a secure home newtwork. You should have a router that can accept a direct ethernet cable. If you are working at an office, the network configuration settings I've outlined here might have to be adapted for your specific company's network/firewall.

Step 1: Gather Materials

We need the following:
  • The Raspberry Pi itself
  • A power supply with a micro USB cable to power the Pi. Get a 2A one if at all possible
  • An 4gb SD card. For most cases, there isn't a need for anything larger.
  • A USB wifi dongle. There are many of these that are Pi-compatible on the market
  • An ethernet cable to go into your home router
Not pictured, but needed: an HDMI monitor with an HDMI cable, a keyboard and some sort of ethernet router than lets you plug an ethernet cable directly into the back of it.

Step 2: Download Raspbian

Unless you need special Linux capabilities, Raspbian is the recommended Linux kernel to install.

Download the latest package here: http://www.raspberrypi.org/downloads

Make sure you double-click the downloaded .zip so that you have a .dmg file. For the purposes of this Instructable, I leave the .img in my downloads folder.

Note: I'm using a Mac as my host computer, but most of these instructions can be adapted for other operating systems.

Step 3: Initialize SD Card Using Disk Utility

Use Disk Utility to initialize your SD card. It doesn't matter what the name of the card is.

What does matter is that the format is MS-DOS (FAT). Format the SD card. It will only take a few seconds.

Quit Disk Utility when you are done.

Step 4: Copy the Raspian Image Onto Your SD Card

Open the Terminal application on the Mac, which will be in your Applications folder.

For those of you unfamiliar with using this app, Terminal provides a command-line for controlling the underlying Unix operating system on Max OS X.

Type in (then press enter):
diskutil list
This will list all your mounted drives. You will see something like the image above: a list of drives with different partitions on them. You want to find the information pertaining to your newly-formatted SD card. In my case it is /dev/disk1s1. This may be different on your computer.

Now, unmount the disk using the Terminal command:
sudo diskutil unmount /dev/disk1s1
The device /dev/disk1s1 is from my setup — yours may be different. Important: use the right device name on your system.

The preceding sudo command stands for superuser do. These are commands that can wreak havoc if misused, so will require your Admin password.

You'll be shown a message that your SD card has been unmounted. Its disk image will disappear from the desktop.

Here's where you want to pay close attention. We want to type in a command such as:
sudo dd bs=1m if=~/Downloads/2014-01-07-wheezy-raspbian.img of=/dev/rdisk1

Note that we are using the "raw device", which means that the name /dev/disk1s1 maps to /dev/rdisk1. Make sure you specify the appropriate raw device, i.e. if your SD device info from diskutil list is /dev/disk3s1, use /dev/rdisk3 for the dd command.

Also, the filename or path for your wheezy-raspbian.img might be different that the one listed here, so please change it accordingly.

Terminal will ask you for your admin password since this was a sudo command. Then you will have to wait long awhile. There is no feedback that any copying is actually happening. This takes something like 30 or 45 minutes. Go have lunch.

Behind the scenes: what the dd command does is copy the disk image and do any necessary conversions.

Once the dd process is done, Terminal will show you how many bytes were transferred to the SD card (about 2.9 gb). Eject the new SD card, which will be now mounted on your computer and be titled something like boot.

Congratulations, you have a bootable SD card for your Raspberry Pi!


Step 5: Basic Pi Configuration

Put the SD card in your Raspberry Pi, connect the keyboard, connect it to your HDMI monitor and plug in the USB power. leave the wireless USB dongle disconnected.

You'll see a black screen with a bunch of text, which shows all sorts of configuration details that you don't need to worry about.

You want to get to a Raspberry Pi configuration screen. Some versions of Raspian will load this screen automatically.

If you don't see this screen — and have to do a login (default user = pi, default password = raspberry), you can still get to it on the command line, type in:

sudo raspi-config

You'll see the configuration screen only the first time.The options are, and the exact configuration screen may be slightly different from this Instructable, as the Raspian builds change over time:


1. Expand Filesystem: no need to do this — some may disagree on this point

2. Change User Password: recommended to change this, as using the default password can cause security concerns

3. Enable Boot to Desktop/Scratch: by default, this is set to console, which is what we want to keep

4. Internationalisation Options: set your timezone (if in the US, choose America, then find the correct city with your timezone)


5. Enable Camera: no (you can always change this later)
6. Add to Rastrack: no
7. Overclock: this is up to you, I usually choose Medium, which makes the Pi run a little bit faster at the expense of power and potential component damange
8. Advanced options: choose A4 SSH -- this will enable secure shell access, which means that you can control your Raspberry Pi from a remote computer (extremely useful)

Choose Finish and reboot

When you get to a prompt, enter:
sudo nano /etc/default/keyboard
change XKBLAYOUT to ="us" — assuming you are in the U.S., but you can set this to whatever the keyboard code is for your country. Here is a list of country codes from Wikipedia, use two-letter lowercase ones.

nano is a simple built-in editor. Type in ctrl-X and Y and overwrite to save the file.

Make these keyboard changes take effect by rebooting:
sudo reboot



Step 6: Setting Up Auto-login

Your Raspberry Pi will be without a keyboard and without a monitor and accessible only by ssh — at least that's the setup that I'd recommend using. For that reason, we want to set it up to automatically login.

For older installations (pre-Jessie):

After the reboot, at the command line, enter:

sudo nano /etc/inittab
now, scroll down to the line:
1:2345:respawn:/sbin/getty 115200 tty1

and comment it out by putting a '#' in front of it, such as:
#1:2345:respawn:/sbin/getty 115200 tty1

don't worry if the 115200 reads as 38400 or anything like that, we're just looking for the 1:2345 line

now add the line, beneath it:
1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Be super-careful to get the spaces exactly right.

sudo reboot


and the pi should automatically login.

For newer installations (Jessie):

You can set up auto-login through the raspi-config screen

sudo raspi-config

Choose (3) Boot Options
Choose (B1) Desktop / CLU
Choose (B2) Console Autologin

Choose and yes to reboot

Step 7: Download an IP Scanner Package

If you're like me, there is no computer monitor near the ethernet jack. There's ways to get your Raspberry Pi ethernet address through using commands like ipconfig and hook the Pi directly to a monitor. This technique bypasses the lugging the monitor around the room.

My preference is to use IP scanning software on my laptop to identify the local IP address of my Raspberry Pi.

My weapon of choice is Angry IP Scanner which is a cross-platform, donation-ware tool. It has been working great on my Mac.

A note about IP addresses — and this is a broad topic — but the Raspberry Pi will be assigned a local IP address, or one on your private network. It will be IP-addressable, just like a networked printer, but not able to be directly accessed outside of your network.

For most of us, these are a 24-bit block of IP addresses in the: 10.0.0.0 - 10.255.255.255 range.

Step 8: Determine the IP Address and Ssh Into It

Connect the hard ethernet jack from the router to your computer and plug in the Raspberry Pi.

In this case, the pi has been assigned to 10.0.1.25, as we can see by the scanner (you'll get an error if you try to ssh into the other ip addresses). With the scanner packages, make sure to scan in the range of 10.0.1.0 - 10.0.1.255.

What we want to do is to log into it via ssh and finish configuring it for a static and wireless IP address.

Open Terminal and type in.
ssh pi@10.0.1.25
You may have to say "yes" to an authentication screen, but eventually should be able to get in with your password (hint: the default password is raspberry).

Congratulations, now you can ssh into your Raspberry Pi from any laptop on your network.




Step 9: Run Package Updates

On the command line, type in:
sudo apt-get update
then type in
sudo apt-get upgrade
Both of these commands will give you a lot of gobbledygook. You will wait awhile. Be patient. These update package lists from the various repositories and updates them to get information on the newest versions of packages and their dependencies. 

when done:
sudo reboot
You'll have to relogin via ssh. Hopefully, the same ethernet address will work, but possibly not, in which case you'll want to use the IP scanner again.



Step 10: Clone the SD Card

This step is optional and should be used if you are making more than one Raspberry Pi SD card. It will save lots of time. Otherwise, skip to the next steps on IP configuration.

What we do have is a fully-working Raspberry Pi setup, with auto-login, custom passwords, correct time zone and keyboard settings. We want to clone this setup so that we can bypass the hassle of going through the set up for each SD card: auto-login, time zone, updates, etc.

Since the static IP addresses wired & wifi are unique for each card, we will just add these individually.

Remove the SD card from your Pi and put it back into your Mac.

Launch Terminal and type in:
diskutil list
You've seen this before but now we have some slight differences in the partition name for the SD card. We don't convert to the raw device name this time, just use /dev/disk1

Type in the dd command, like this:
sudo dd if=/dev/disk1 of=~/Desktop/pibootable.img
This will copy the SD card image onto your desktop. For making new RPI SD cards, you would copy this Image onto your a new SD Card instead of the Wheezy image. You would then be able to proceed directly to the IP configuration steps.

Step 11: Assigning a Static IP

At this point, you still don't have your wireless USB adapter plugged in. What we ultimately want is a static IP assigned for every SD card. This way, when we ssh into the Raspberry Pi, we always know which address to use. Also, there won't be any collisions or confusion on the network. 

In theory, you could have a two Raspberry Pis and 10 SD cards. The IP settings will be stored on the SD card itself.

Put the SD card back in your Raspberry Pi.

Connect it with the ethernet cable to your router. Leave the wi-fi dongle disconnected.

Use ssh to get back to logging into your Raspberry Pi, i.e.
ssh pi@10.0.1.25
(or whatever address your IP scanner shows)

Type in:
sudo nano /etc/network/interfaces
You'll see some various settings that look like the image here.

We want to replace the line: iface eth0 inet dhcp
with: iface eth0 inet static

and then specify the address, netmask, network, broadcast and gateway, like this:

iface eth0 inet static
address 10.0.1.64
netmask 255.255.255.0
network 10.0.1.0
broadcast 10.0.1.255
gateway 10.0.1.1

What this is doing is instead of using DHCP, which dynamically assigns IP addresses, it assigns a static one: in this case it is 10.0.1.64

I picked this one because it is well out-of range of the lower IP addresses, which my network will assign for laptops, printers, etc. You can use a different IP address, if you want. This is just one that I've chosen that is out of collision range.

Before you save these changes, keep a copy of the text of the original /etc/network/interfaces file. You can copy-and-paste this in a text file on your local computer.

note: this is the technique that works on my home network. It may not work on yours, though it has worked for others.

Cntl-X, Y and Return to save and overwrite the file.

Now:
sudo reboot
Fingers crossed. Wait for a few minutes and see if can ssh into this new IP:
ssh pi@10.0.1.64
If asked for the RSA fingerprint, say yes.

If you have troubles, you can use the IP scanner. Real trouble and you might have to do go back to the monitor.

Step 12: Adding Wi-fi Support

At this point, you have a cable running to your Raspberry Pi. If your wi-fi dongle conks out, you can always go back to the cable. The static IP number will always be the same.

Time to specify the same static IP number for wireless.

Type in:
sudo nano /etc/network/interfaces
You'll see your edited file, like the image here.

find the line:
allow-hotplug wlan0

above it, add:
auto wlan0

then below it add:
iface wlan0 inet static
        wpa-ssid "yournetworkname"
        wpa-psk "yournetworkpassword"
address 10.0.1.64
netmask 255.255.255.0
network 10.0.1.0
broadcast 10.0.1.255
gateway 10.0.1.1

for wpa-ssid, add your network name
for wpa-psk, add your network password

** Unplug the power from the Raspberry Pi. Plug in your wi-fi dongle. Unplug the cable. Now log in via ssh. 

Once again, this work on my network, which uses standard WPA security. If you have a hidden network or additional security, then you'll have to do a bit more research to get these settings right.


Step 13: Done + Troubleshooting Tips

You're done!

For multiple SD cards, you'll want to use different IP addresses. I use a label-maker and adhere the IP addresses to the back of the SD cards, so I never get confused.

You're off to the races! Have fun.

RSA Key Troubleshooting
If you ever get this dialog in the Mac Terminal Window, it's super-confusing.

What this means is that you've used this IP address for another SD card and now you're trying to use it for another one. It won't let you in.

On the Mac, you'll want to delete a file called known_hosts, which is in a hidden .ssh directory on in your User folder. 

More Troubleshooting
The wi-fi configuration with the Raspberry Pi is definitely the trickiest portion of it. This technique works reliably for my home network, as well as several others that I coached through. I'm by no means an expert, so if you get stuck, you'll have to do some creative sleuthing.

I hope this was helpful!
Scott Kildall

For more on Raspberry Pi code and other projects, you can find me here:
@kildall or www.kildall.com/blog

2 People Made This Project!

Recommendations

  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Audio Contest 2018

    Audio Contest 2018
  • Optics Contest

    Optics Contest

52 Discussions

0
None
megan_stapley

1 year ago

Would someone be able to explain this direction in step 8: "Connect the hard ethernet jack from the router to your computer and plug in the Raspberry Pi". I'm not really sure where we are meant to plug the raspberry Pi...does he mean into the computer or just plug in the power?

0
None
henryv26

1 year ago

Fantastic guide, thanks for the effort you put into this. Can you recommend a procedure to assign a static IPV6 unique address to each SD Card Clone and then taking that IPV6 address and renaming the" hostname" to match IPV6 address using some kind of automated or scripted procedure

0
None
ThundrV

1 year ago

Amazing guide! Just used it to set up my R-Pi + Android SSH access.

0
None
engdar

1 year ago

Hello. Is it possible to set up the raspberry pi for the very first time without an Ethernet? Like a WIfI dongle?

0
None
pro1962

2 years ago

hi all ,, i just got my new raspberry pi b ,, some thing happen i do not understand ,, it installs the os not a problem , but i do not do a thing , no passwords, or typing , startx , so when i boot up it just goes to the main screen ,, maybe you might tell me

6 replies
0
None
scottkildallpro1962

Reply 2 years ago

Hi, I'm not sure exactly what you are asking :)

What is the "main screen"? Did you use this configuration guide? Did you get a command prompt?

0
None
pro1962scottkildall

Reply 2 years ago

hi mate ,, i just reformatted the sd card and put the noobs i got of raspberry pi site , i looked at the files, it has the winzip file in there ,, should that be there as well ??

0
None
pro1962scottkildall

Reply 2 years ago

the first time it boot up with no command prompt ,, so i sent the person a email who i got it of what to do, he told me to format the card and down load it again ,, which i did . after the format i made Shaw the card was empty , got on the raspberry site and down loaded it again . this time still no command prompt. just goes to the main screen with the rasp berry on it menu , files scratch wolfarm . so i do not really know if it all set up at all. i open some files like tools ,, nothing in there , so i really do not know what its doing .

0
None
pro1962scottkildall

Reply 2 years ago

hi and thanks ,, i did not get a command prompt , it just went to the screen with the raspberry on it

0
None
scottkildallpro1962

Reply 2 years ago

sounds like there is some sort of OS install issue. Are you installing just like the Instructable or running off the package? If the former, I'd try the steps once again starting from the SD card formatting.

0
None
MarkovKane

3 years ago on Step 12

I typed the wif page on step 12 exactly like it is in your thing but using all my ip info, and it didn't work for me, and now all my wifi settings are lost.

2 replies
0
None
nevyn.hiraMarkovKane

Reply 3 years ago on Introduction

Also, be aware that wifi support is going to be dependent on your dongle. For a lot of hardware, the vendors don't supply support so it takes volunteers to add that support. Other times, that support does exist but not in a "plug'n'play" type fashion i.e. it may require manual compiling of modules (well outside of scope if this is your first time playing with Linux) or installation of a dkms package (this gets complex as well but no where near as complex as compiling your own).

Linux does support more hardware out of the box BUT it's often slower to get the support to make newer (and/or troublesome) hardware work.

0
None
joedixMarkovKane

Reply 3 years ago

In step 12, after changes are made and before you pull the power, do this.
1. Press 'crtl + x' to close nano, 'y' for yes to save, and enter for same filename.
2.type 'sudo shutdown now -h' to shutdown and halt.
Now proceed with removal of the power....

0
None
Musclebear2b

4 years ago on Step 4

I'm a mac user too, and I found, through all my searching for ways to do it, Apple Pi baker - http://www.tweaking4all.com/hardware/raspberry-pi/...

Its a nice easy GUI way to format an sd card in preparation for flashing an img onto, flashing imgs to sd cards, and cloning them for backups.

Flashing a NOOBS image takes only a few minutes, and works perfectly every time.

3 replies

Thanks for sharing! Looks like NOOBS is a solid, useful GUI solution.

My guide is definitely all about the command line, which is good...if you want to get in deep and learn more about the command line.

This will flash any img to an sd card, not just noobs. But it only works on mac

I'm pretty much a noob myself at all things pi, and I recently ordered an lcd touch screen for mine, and the instructions given aren't particularly in-depth for installing it onto an existing build, so I was practicing on a new build.
There is an img with the lcd driver already, but being a noob, each tweak I made changed something that stopped the screen working properly, so I reflashed the sd card a lot. Not something I'd want to be doing if it took 45 minutes each time!

I'm all for learning to get to grips with the command line - in fact, I've just installed debian onto an old vista laptop so I can practice - but when you're new to something, you want quick and easy successes which encourage you to learn more, rather than drawn out boring processes...

0
None

:) My introduction to Linux has a long one full of dial up speeds and wanting to learn it *all* now! I ended up playing with Linux from Scratch and

Best tips for your situation:-
* If you're doing things like compiling modules and mucking around with the kernel. This is really hard and chances are you're going to find yourself often more frustrated than not. In this scenario, once you've imaged one SD Card, image a second one... So while you're mucking around, you're also creating a whole new SD Card which means your mucking around need never stop!
* If you are compiling modules.... chances are someone's already gone through all the pain. Look for ppa's (personal package archives) and the like.
* Otherwise, keep a pen a paper handy and take note of your changes. Since 90% of Linux can be configured via text files, reversing changes is also fairly trivial.

0
None
kd7eir

3 years ago on Introduction

If you are going to hook a monitor up at the beginning, why not do all of your configuration that is possible through the monitor?

If you do not have an HDMI monitor, then simply connect to the Pi with a serial cable, use Putty to connect to it, and then configure it from there. I just do not see the point of using the monitor for one step, and then resorting to command line configuration for everything else, particularly for new users.

Is this instructable meant to be more of a lesson in linux command line configuration than an actual Raspberry Pi configuration guide? I just cannot wrap my head around doing things the hard way. Configuring wifi when you have a monitor attached takes about 15 seconds and shows you the assigned ip address, eliminating the need for additional software, an ethernet cable, and "treasure hunting" for the ip.

Please enlighten me as to why this instructable takes the most difficult route to accomplish it's task, adding onion-like layers to what can truly be a simple task.

1 reply
0
None
scottkildallkd7eir

Reply 3 years ago on Introduction

It would be helpful if you were to actually provide the specific steps to accomplish this, rather than just critiquing the Instructable itself.

Do realize this: I am no expert.

I would like to help others make Pi-based projects and will suggest alternatives, as needed.

Remember, be nice. We're all on the same side here.