In this series of blog posts I’m going to show you how to do the initial setup of your Raspberry Pi over your network. That is to say, without the need for your pi to have its own keyboard and monitor (headless). This tutorial is for those running Ubuntu Linux on the computer connecting to the pi, but the steps are very similar if you have some other Linux distribution (or different operating system).

In this series of blog posts I’m going to show you how to do the initial setup of your Raspberry Pi over your home network. That is to say, without the need for your pi to have its own keyboard and monitor (headless). This tutorial is for those running Ubuntu Linux on the computer connecting to the pi, but the steps are very similar if you have some other Linux distribution (or different operating system).

Hopefully, all the bits you need have turned up (see my previous post o Buying a Raspberry Pi), else you’re going to struggle a bit. As well as your pi, you will also need a computer that has a SD card reader and is running Ubuntu, an internet connection and a spare network socket (either on the Ubuntu computer itself or on your router/network switch).

I’m going to assume you have the Raspberry Pi model B board (the one with the network socket), as this is by far the most common option, but if you have the model A board, just plug a compatible ethernet adapter into the USB port and everything will be the same (Nb this probably won’t work with a wireless adapter, as it would need to be able to connect to the correct wireless network before you have configured it.)

I’ll go into a bit detail about the commands we are going to run so you understand why we are doing what we are doing. You don’t need to know this stuff, but I think it’s interesting, so I’m going to tell you about it anyway!

Once the pi’s basic setup is done, you can then check out my other blog posts to learn how to turn your Raspberry Pi into a NAS/fileserver, media centre, dlna server and/or football playing robot!

So, the first thing we need to do is download and install the Raspberry Pi’s operating system. For general purpose and/or NAS/fileserver usage you want to install the Raspbian distribution. If you are fairly new to computers, don’t worry too much about the terminology, you’ll get the hang of it. Plus, people (especially marketing people) misuse the terms so much that you can interchange things a lot anyway and no one is going to mind.

Now then, if you’re going to install an operating system, it is probably useful to know what one is. An operating system is a collection of computer software that is responsible for the basic functionality of a computer. It includes a kernel (which manages the computer’s resources and allows other programs to access them), device drivers (which allow the kernel to talk to the various bits of the computer, like your keyboard and mouse) and basic system libraries and applications that allow for things like reading and writing files. An operating system bundled together with a useful selection of more high level applications (such as word processors etc.) is known as a distribution.

There are various ways to install a distribution, we are going to use an image file. An image is a copy of a disk, in this case, one which has our operating system and some useful applications from our distribution already installed on it. The image is installed by simply writing it directly to disk (in this case, your SD card.) Be aware that this isn’t the same as copying the image file to a disk, the difference will (hopefully) become clear latter on. Anyway, using an image file will give you a working computer without having to deal with tricky install issues, like how do you install programs on your computer when one of the programs you need to install is the program that installs programs!

So a quick recap.

Kernel

does all the very basic stuff, like accessing the processor.

Device drivers

software that enables the kernel to talk to the hardware in your computer.

Applications

programs that do stuff, can be simple or really massively complicated.

Libraries

collections of useful application fragments so that each application doesn’t have to duplicate the same code.

Operating System

kernel plus device drivers plus basic system applications and libraries (there is no consensus about what constitutes a basic application).

Distribution

operating system plus collection of high level applications.

Image

a copy of a disk that can be copied to another disk. In this case, our image is of a disk that has the Raspberry Pi’s operating system installed on it.

Now you’ve got that clear, I’ll add a bit confusion back: Microsoft’s well known Windows software started life as an operating system (called DOS) but has grown into what would be better described as a distribution yet is still commonly referred to as an operating system.

As for the Pi, it uses the Linux kernel, and the GNU basic system applications, commonly known as GNU/Linux or just Linux. Linux is packaged with user level applications for the pi by a few distributions: Raspbian, Arch Linux and Android, to name a few. Of the different distributions, there are a few different images you can get, which have different default setups, but don’t worry about them for now. Just go get the default Raspbian Image from www.raspberrypi.org/downloads (using your Ubuntu computer).

At the time of writing, the current version is 2012-12-16-wheezy, but get what ever is the latest version. Use BitTorrent if possible. BitTorrent is a clever way of sharing the downloading of data between the people downloading it (typically servers have problems when new software etc. comes out, as suddenly lots of people try download it at the same time, putting huge demands on the server. With BitTorent, the more people who download something, the more people there are to download it from, so it actually gets quicker to download something the more people that download it!)

Note that when you click on the torrent file on rasperrypi.org, you need to select open rather than save. The torrent file isn’t the image, it is a file that tells the BitTorrent client where to download the image from.

Ok, so now you have your Raspbian image. For the sake of completeness lets verify the download (you can skip this if you can’t be bothered). Verifying the download is important for two reasons. Firstly, it makes sure the file didn’t get corrupted whilst it was downloaded. If the file got corrupted and you tried to install without knowing, at some point you would get very strange problems that might be difficult to track down. Secondly, for the security conscious amongst you, verifying the file makes sure that no malicious person has cunningly replaced the Raspbian Image with their own version whilst the file was downloading.

To verify the file, you create a checksum and compare it to the checksum of the original file posted online. A checksum works by treating the data as numbers and adding them together to get a large number. This number is generated in such a way that it is practically impossible to change the original file without also changing the checksum. The checksums used by raspberrypi.org have the funky title SHA1, and unsurprisingly, the program you use to create and check the checksum is called sha1sum.

So here we go…

Phew. No one has tried to infiltrate my home network by tampering with the Raspian Image. Hang on, though. If someone was sophisticated enough to modify the file I was downloading, perhaps they could alter the webpage that has the checksum on it and alter that too…

Ok, I’ve recovered from my paranoia. Let’s get this sucker installed. Now, there are some nice easy graphical programs for writing images to disk. If you want to take this route, install usb-creator-gtk, but the cool kids are going to do this the low level way from the command line. The program we are going to use is dd. dd is short for data destroyer, due to its ability to destroy all the data on your computer if used incorrectly (well ok, it’s not really short for data destroyer, but the real reason for its odd name has been lost in the mists of time). Now, on linux, all hardware is represented as files that you can read from and write to (if such things make sense e.g. you can play music by copying a suitable music file to the soundcard device file). The same is true of our sd card. Now, you may be thinking, so what? Surely all disks are accessed as files, that’s how come I can copy files from one disk to another. However, what you accessing isn’t the disk directly but a filesystem on one partition of the disk, which has been mounted on the computer’s file hierarchy. To understand what I mean, it might help to briefly explain how a disk looks to the computer.

A formatted disk, like our sd card, is commonly made up of various parts that can be accessed and modified with software. The first part is the MBR (master boot record), which is where information about the rest of the disk stored, including how to boot (start the computer) from it. The rest of the disk is divided into sections called partitions, where these partitions are and how big they are is stored in the MBR. Each disk can have (for historical reasons) four primary partitions. These primary partitions can be normal partitions or extended partitions. Extended partitions can hold additional logical partitions to enable you to get over the four primary partitions limit. Primary partitions are numbered first and the first logical partition is partition five, even if all four primary partitions haven’t been used. In the old days there were rules about what data could be stored where, but nowadays (assuming you are using a common modern operating system and boot loader), the choice is pretty arbitrary.

There are many reasons you might partition a disk into several pieces. The most common reason in a home environment is to ensure that there is space on the disk that is always reserved. This might be so that a laptop can perform a suspend to disk (where it writes the contents of ram to disk and then turns itself off so that when it is turned back on it can resume exactly as it was) or so that you don’t accidentally fill up all your harddisk space, including that needed by the operating system to perform basic functions (though modern harddisks are so huge this isn’t really a concern any more in the home environment) or to allow two different operating systems to coexist on the same disk (though virtualisation, running one operating system inside another, has made this less common, too.)

If you want to have a look at how your computer is currently partitioned fire up “sudo gparted” (if it isn’t installed run “sudo apt-get install gparted” first). Be careful not to change anything else you could completely hose your computer. This is how the first hard drive in my computer is set up:

As you can see I have three primary partitions: one containing my Ubuntu installation, one an old windows installation and one which is an extended partition that contains a logical partition that is a swap partition (swap space is used as virtual ram when you run out of real ram). As I’m only using three partitions, the extended partition isn’t actually necessary and the swap partition could have been created as a primary partition.

So, continuing from my last post, we know that a formatted hard disk is divided into numerous partitions (the minimum number of partitions being one). Each of these partitions start with a bit of information about what type of partition it is and how to boot an operating system off it (if one is actually installed on it), which works in conjunction with boot information in the MBR. The partition then has a file system written to it. The file system includes the information needed to locate and store data (i.e your files) on the partition.

There are lots of different types of file system all with advantages and disadvantages. However, for a desktop user, the most important differences are between what are called journalling and non-journalling file systems, the security features offered by the different file systems and the maximum sizes supported. Of these, maximum size is the most self-explanatory. As disk sizes have increased, so file systems have had to be able support bigger partition sizes, bigger files and longer file names. You can also probably guess what typical security features are supported by modern file systems. Give yourself a pat on the back if you came up with encryption (i.e the ability to encrypt the entire file system not just individual files), file ownership and file permissions (allowing you to specify who should be able to access the files and how). If you came up with any more, well, no one likes a smart-arse! Now, as for journalling, this might need a bit of explanation.

In the old days of computers, if you were copying a file and the computer unexpectedly turned off half way through writing it, it would not only leave the file in an unreadable state but, if you were unlucky enough for the computer to be updating the information about the file in the file system when you it got turned off, it could leave the file system in an unreadable state, meaning you wouldn’t be able to read any of the data stored in the partition. To fix this you would have to repair the file system when the computer was next turned on. This involved checking all the data on it, something which was irritating when disks were a few megabytes in size but something that would take hours on a modern terrabyte one. So journalling file systems were invented. These stored information about what they were doing before they did it so that in the event of suddenly losing power the journal could just be reread when power was resumed and the operation finished or, at least, terminated in a sensible fashion.

You might well think that, because of this, non-journalling file systems are a thing of the past but unfortunately not. Non-journalling file systems are a lot simpler than their journalling counterparts and are, therefore, cheaper/faster to implement. However, more commonly, the problem is that, due to the fact that Microsoft and Apple have their own journalling file systems (NTFS and HFS+ respectively), which they do their best to stop other people using, Linux had to write its own (ext3, now ext4), which Apple and Microsoft don’t want to support because then we’d live in a crazy messed up world where you could buy a usb hard drive with a sane file system on it that you could expect to work everywhere. Instead we live in a world where your memory stick has to have a file system which was outdated over a decade ago just because it is so simple that everyone one has worked out how to use it and is old enough to no longer be covered by patents, meaning you can use it without having to pay.

The upshot of all this is that raspberry pi expects to have at least two partitions on it. One which has an old non-journalling file system on it (vfat) and which contains basic config information for the raspberry pi’s hardware (for example setting the tv standard for the composite out) so that you can do the basic setup needed to actually get it to display something using any computer. As this blog post is dealing with setting up the raspberry pi over the network we don’t need to worry about this at the moment (though we might need to later on). The other which can have any file system supported by the operating system we are going to use, which will, in this case, be a Linux’s standard journalling file system, called ext4.

Because we are going to install the os by copying an image file. We don’t need to actually create the partitions ourselves, so you probably didn’t need to read all that…

Ok the time has come to actually write this sucker to the disk. If you remember, we are going to do this using dd, and we’re using dd (a) because we’re cool and (b) because the image doesn’t just contain the files but also the MBR, partitions, and filesystems. Because of this we need a way to access the disk at low level.

On Linux, low level access to devices is provided by the /dev directory. Here you will find your hardware represented as files that you can read from and write to (if it makes logical sense to do so). You will also find in here some virtual pieces of hardware that you might want to have a look at. Some of note are /dev/zero, a device that will give you a constant stream of zeros if you try to read data from it (that is, it will give a constant stream of binary 0, the null character, not the character 0 which is represented by the binary number 48, which can be a bit counter intuitive) and /dev/null, a digital oubliette, which makes any data you write to it vanish.

By default, ordinary users can’t access a lot of these files, as this would pose both a security risk, as reading directly from a disk would enable you to bypass system security, and a risk of someone accidentally screwing up your system by deleting something they shouldn’t, so when we write directly to the SD card, we are going to be using the sudo command to give us permission to do so. Now, be careful. If you make a typo, you can destroy all the data on your computer! Who thought copying a file could be so exciting?

So the first thing to do is fire up a terminal. If you haven’t changed any of unity’s default shortcuts, ctrl-alt-t will fire up a terminal. Add it to the launcher permanently whilst your about it by right clicking on it in the launcher and selecting lock to launcher. We’re going to be using the terminal a lot, cause that’s how we roll.

Now you’ve got your terminal up, have a quick look in the /dev directory to get yourself acclimatised by running ls /dev. The first thing you’ll probably notice is that quite a lot of things in there have odd names (not to mention the “ls” command itself and the /dev directory). This is because, when these names were standardised upon, space was at a premium, so they were abbreviated (“ls” is short for “list” and “dev” is short for “devices” in case you were wondering.)

Oh, before we continue, I’d better mention the forward slash, “/”, that comes before “dev”. This is known as a directory separator and is how you tell the computer that one directory is inside another. In the case of “/dev”, it isn’t inside any directory, it is a top level directory, and is therefore preceded only by a forward slash. In the case of the “null” device we talked about earlier, it resides in the “/dev” directory, so when we write it, we separate it from “/dev” with a forward slash: “/dev/null”.

Now, you my well wonder where you’ll find your SD card in amongst the rest of the contents of “/dev”. As its exact location depends somewhat on what other hardware you have in your computer, the best way to find it is to take a quick look at one of the log files. So you don’t have to scroll about trying to find the entry in the log file, if the SD card is already inserted, take it out it, wait a couple of seconds for ubuntu to unmount it, and then push it back in. If it isn’t inserted, just push it in. This will cause Ubuntu to auto-monut the SD card and (unless you have changed the defaults) also open up a new nautilus window to show you what is on it. Now would be a good time to make sure you don’t have anything on the card you want to keep, as all the data will be lost when you copy the raspbian image onto it. The close the nautilus window. Ok, now to see where in the /dev/ directory our SD card ended up.

The log we are going to check is the device driver message log or dmesg for short. This is a handy log that stores the output of the various devices on your computer. It is often a good place to start if something isn’t working as would expect before delving into the more specific logs that are store in “/var/log”. To access the dmesg log you simply type dmesg. Rather a lot of information about everything that has happened since the computer was booted will scroll past you, which you can have look at if you’re interested, but what we specifically want to see is the last few entries that refer to our SD card we just inserted. Here is what I get:

Here we can see that the mmc driver has found a new SD card (in this case a high capacity SD card, a SDHC card), that it has called it mmcblk0 and that it has two partitions (p1 and p2) on it. If you’re using a brand new disk you’ll probably only have one partition, but if you’re repurposing an old one it might have anything on it (but hopefully nothing you want to keep as it is all going to be deleted!)

The first thing to do is to unmount the two partitions that were just auto-mounted, just in case the computer tries to read or write from them whilst we are monkeying about with the disk. So at the command prompt, type umount followed by the name of the partition you want to unmount (no one knows why the umount command isn’t called unmount). If umount completes succesfully, like most commands it will be eeirly silent. It’ll only tell you if something goes wrong.

Right, getting back to the /dev directory, we have seen that my SD card can be found in /dev/mmcblk0 (and that the first partition will /dev/mmcblk0p1 and the second will be /dev/mmcblk0p1). Now, and this is important, just because this is the name of the device on my computer, doesn’t mean it will be the name of the device on yours, especially if you have another removable device plugged in! Make sure you check, or you risk losing all your data. One simple way to check you’ve got the right device is to remove the SD card and check that the device files vanish too.

So, we are almost ready to write this sucker to the SD card. First though, we’d better just check that the device files are there as we expect them to be. Use “ls” again to do this. Above, you can see I used what is called a wildcard in my command, the “*”, to limit the amount of information output by “ls”. This particular wildcard will match any number of any character. That is to say that ls /dev/* would match every file in the /dev directory, whilst ls /dev/a* would match everything in the /dev directory that’s name began with a lower-case “a” and so on. In my case, I used it to macth only those things that began with “mmc”.

Now you’ve done that and are sure of the device file for your SD card, we just need to decompress the image file we downloaded (nb. since starting these posts a new version of the image file has been released so from now on I’m using the 2013-02-09 version). Now the adventurous amongst you might want to decompress the image file on the fly (hint, you want to pipe the output of the unzip program into input of dd), but I think the rest of us have had enough excitement for one day so will just decompress the image file first. To do this you just use the unzip program with the path to the downloaded zipped image file as below (by default, unzip unzips the file into the directory you are currently in), and then it is the moment of truth.

dd takes a few arguments that we are going to use: “if”, which stands for “input file” (the image we downloaded); “of”, which stands for “output file” (the SD card device file); and “bs” which stands for “block size” and represents how big a chunk of the file will write in one go. The “bs” argument isn’t really needed, it just speeds things up a little. The syntax of dd’s options is a little unusual: usually commands have the form –option=value or -option value, but dd uses option=value. It is just one of those things. Anyway substitute the correct values for your system, remember this might take a while to complete and that silence means it is working and not finding any errors, and here we go…

Still have a working computer? Good. Now you can stick the SD card in the pi and have another working computer! First though, if we want to be able to do anything useful with it, we need to connect it to the network. The pi’s default networking setup sets it to wait for a piece of software called a DHCP server to give it details about the network it is going to connect to. If you have a standard home network, your router is the DHCP server. If you are on a larger corporate network you might have a standalone DHCP server. In either case, just plug the pi in with a standard network cable, and when the pi is turned on, the DHCP server will do its magic.

If you don’t have a router or a spare network socket on it, a couple of clicks will set up your computer as a DHCP server and share its internet connection with the pi. To do this you need to plug the pi directly into the network socket on your computer using a crossover cable It has been pointed out that the raspberry pi’s have auto-sensing ethernet ports and so you do not need a crossover cable.

If you look closely at the two cables above, you can see that in first cable (the blue one) the colours of the wires are the same on both ends, but on the crossover cable (the grey one) some of the wires in are different positions (namely 1,2,3 and 6). If this were for a gigabit connection, all 8 wires would have to be crossed, but as the pi doesn’t support gigabit speeds, this doesn’t matter to us (nb a gigabit crossover cable is backwards compatible with the older, slower connections). The first cable, often called a patch cable, is used when connecting a computer to a hub/switch/router etc., the second, the crossover cable, is used when connecting a computer to a computer, or a hub/switch/router to a hub/switch/router (nb lots of modern devices can auto sense what sort of connection you have so a crossover cable isn’t always needed anymore).

If you need to setup a shared connection to your pi, as just discussed, do it now by clicking on the networking icon in the top right hand of your screen (its exact look depends on what theme you are using and if you currently have a working connection), select “Edit Connections” from the drop down list that appears. In the dialog box that pops up, making sure you are on the “Wired” tab, click “Add”. Give the connection a name, such as Shared, click on the “IPv4 Settings” tab and select “Shared to other computers” (all the other fields can be left as they are, though if you aren’t going to be leaving the pi connected to the computer in this manner permanently, you might want to uncheck “Connect Automatically”). Then click ok.

Now click the networking icon again in the top right hand corner, and this time, select the connection you just created (you might first have to disconnect a wired connection if one is set to connect automatically). This will set up a small network consisting of your computer and the pi that is connected to your main internet connection (if you have one). Of course, none of this will actually happen until you turn the pi on, which we are going to next.

So, now you have the correct sort of network cable plugged into your pi and either your router, network or computer, the fun begins. Plug in the power supply and turn it on. Wohoo! You now have a working Raspberry Pi (for a somewhat limited definition of working.) Let’s configure it.

The first thing we need to do is find out what details the DHCP server gave the pi so we can find it on the network. Specifically, what we need is its IPv4 address. You can think of an IP address of a computer as being somewhat analogous to the postal address of a house. In the same way as a postal address starts by narrowing the location of the house down by road and then the exact house in the that road, so the IP address narrows down a computer’s location by network segment before identifying the exact computer on that segment. It’s probably a good idea to have a quick look at an IPv4 address now so we know what we are talking about.

Here is a typical one: “192.168.0.2”. Each block of numbers goes up to 255. Which bit of the address corresponds to the road name and which bit house number is determined by the network mask. For example a network mask of 255.255.255.0 means that the first three numbers are analogous to the road and the final one to the house number, whilst 255.0.0.0 would mean that only the first number is analogous to the road and the final three to the house number. Thus, given a network mask of 255.255.255.0, 192.168.0.2 is on the same “road” as 192.168.0.3, but on different “road” to 192.168.1.4 and, therefor, cannot talk to 192.168.1.4 without the use of some sort of linking device.

Those of you who are quick at math might have worked out that this means there are around 4 billion possible addresses. These have all been used. As a result, IPv4 is in the process of being replaced by IPv6, which increase the number of address to 340 undecillion (7.9×1028 more than IPv4) or “a lot more” if you prefer. This process is likely to take a good few years. At the moment, it is still much more common for people to use IPv4 so that is what I’ll cover here.

Private networks that are not connected directly to internet (e.g. your home network, which is connected to the internet through a router) have special addresses reserved for them. These are 192.168.0.0–192.168.255.255, 172.16.0.0–172.31.255.255 and 10.0.0.0–10.255.255.255.

So getting back to our pi, we know that the IP address assigned to it must be in one of these three ranges and, if you are on a typical network, both your computer and your pi have to be on the same network “street”. Depending on how you connected your pi to the network, there are three different ways in which you go about finding the pi’s address. I’m going to deal with the three cases separately, you only need to follow the one that applies to you.

1) Computer and pi attached via a crossover cable.

This is the easiest case to deal with. You just need to look in the log on your computer to find the address. In your terminal type tail /var/log/syslog. The tail command shows you the last few lines of a file (ten by default). Look out for a line with dnsmasq-dhcp. If you plugged and turned on your pi awhile ago, the relevant line might not be in the last ten. In this case you can use grep, a massively handy little program, to print out the lines from the syslog that contain dnsmasq-dhcp, grep dnsmasq-dhcp /var/log/syslog.

2)Pi attached to (simple) local network and you have access to router.

This is also pretty straight forward. You just need to log in to the router and have a look at its log file.

First we have to find the IP address of the router, the default one is probably written on the side of it. If not, bring up a terminal and type route this brings up the routing table. The default route will be your router (the default route is the one your computer uses if it is looking for a computer that is not on the same network “street” as you, such as a computer on the internet). Mine is 192.168.1.254, though it is more common to use 192.168.0.1.

To log into the router, type the IP address you found via the route command into your web browser. Enter your user name and password (the defaults, again, are often on the router or in the documentation you received with it, else a quick google will tell you.)

As there are so many different routers on the market, I can’t tell you exactly where to find the information you are looking for, so you might have to poke about it to find it. On mine, it can be found in several places. “Attached Devices” is the simplest.

3) Pi attached to a network (including large corporate one) where you don’t have access to whatever gave the pi its IP address (or if you just want to do it this way for fun).

In this case we can’t just look at a log file to work out the IP address. We are going to have to be a bit sneakier. What we are going to do is scan the network till we find it. Be warned, if the network isn’t yours, doing so might be frowned upon by the IT department and be against company policy, as it is the sort thing someone might do if they were trying to get information about the network in order to hack it.

That being said lets see how we do it. First of all, install zenmap: sudo apt-get install zenmap (zenmap is a graphical frontend for nmap, those who wish to stay hardcore can just use nmap instead), and then fire it up as root (if you can’t run zenmap as root, it won’t be able to identify the pi using its mac address. In which case, you’ll have to keep an eye out for a computer with just one open ssh port. If it is a big network with lots of computers that match that criteria, you may want to run a more thorough scan to help you identify it).

In the target box you put the address of the network segment we are interested in. The pi is going to be on the same one as your computer, so we can use its address and network mask as the target. To get this information, type ifconfig at the command prompt.

Here you can see I have three network devices: eth0 (my ethernet card), lo (the loopback interface, which the computer uses to talk to itself) and wlan0 (the wireless card). You might have slightly different network interfaces depending on what hardware you have. We are interested in the interface that is connected to the same network as the pi, in my case, wlan0. We can see its IPv4 address is 192.168.1.16 and its netmask is 255.255.255.0. We therefor know that the pi must have an address somewhere between 192.168.1.1 and 192.168.1.255. There are various ways we can enter this into zenmap, but the most intuitive is to use the asterisk as a wild card thus, “192.168.1.*”.

It is up to you what level of scan you run, but a quick scan will get you the information you need. The fuller scans can take a long time if you are on big network, but it is quite interesting to see how easy it is to discover things about the network. Anyway, click the scan button and wait for the pi to turn up.

Ok, we have the pi powered up, plugged in and have figured out its IPv4 address. Now we can log into it over the netwok using ssh, the secure shell. A shell is a command line interface to a computer (though, as we’ll see in a minute, ssh can be used to run graphical programs, too, and a lot else besides), and the secure bit in ssh’s name, rather unsurprisingly, means that all communication using it is encrypted.

Starting ssh is pretty straight forward:

ssh [options] username@remote computer

By default your Raspberry Pi has the username:pi and the password:raspberry. We don’t need to give ssh any options at the moment, so the complete command looks like this (though obviously you need to substitute my ip address with the one you found in the previous article):

ssh pi@10.42.0.68

As this is the first time the pi has been connected to, ssh will tell you that, “The authenticity of host [host name] can’t be established”. You don’t need to worry about this. This is caused by the chicken and egg problem of setting up secure communication, where you can’t identify a computer till you have connected to it the first time, but you can’t safely connect to it until you’ve identified it. There are really only two solutions to this problem. One is to manually add the identification of the new computer via some other means. The other is to just assume that the chances of someone trying to spoof being the computer you are about to connect to are very small and just trust it the first time (once you have connected to a computer once, ssh can ensure it is always the computer it claims to be), so seeing as it is very unlikely that someone is trying to spoof being the Raspberry Pi at this exact moment in time, it is ok to continue, so type “yes”.

Depending on how your local computer is set up, you may be asked for your passphrase or to set one up. The passphrase is an additional level of security that isn’t required. I’ll talk about it and why it is useful in more detail in a later post. In the meantime, if you have set up a passphrase, enter it; if you haven’t, don’t worry about it; if it asks you if you want to set one, leave it blank for the time being and hit “enter”.

It’ll then ask you for your password on the remote machine. As mentioned before, the default password on the pi is “raspberry”. Type it in and press enter. Be aware that, for security reasons, ssh won’t give you any feedback on the screen as to what you have just entered.

You’ll then be given some information about the system you have just logged into, including the useful advice to set up the pi using the command “sudo raspi-config”, so do that now, and we’ll look at the set up options in the next blog post.

Now the moment you’ve all been waiting for. Your pi is imaged, plugged in, turned on, connected to the network, you’ve found its IPv4 address, logged into it via ssh and you’ve run “sudo raspi-config”, so lets get it configured.

First thing to remember is that this is a text interface so no mouse. You move between the different items with the arrow keys and select them by hitting enter. If you need to select a check box on one of the later screens, you hit space, and when you’re done, you move between the list of actions and the buttons at the bottom by pressing the “tab” key.

The first thing to do is check that we have the latest version of raspi-config (if your pi doesn’t currently have anyway of connecting to the internet, you can skip this). I’m not sure why they decided to put this as the last option, but there you go. This might take the pi a minute. Once it has either found that you already have the latest version of raspi-config or updated it to the latest version, we can continue. We’ll deal with the rest of the options in order.

Info

You can skip the info entry or read it as you wish. Disappointingly, the current version doesn’t have a lot of actual information in there, but if you’re using a later version, then me it might have.

Expand rootfs

This is the first interesting option. If you’ve been following all the way through this series of posts, you’ll know what a filesystem is and understand that the pi has two to begin with (one which holds the operating system and one which holds basic low level configuration details for the pi). The root filesystem is the one the root folder is on i.e “/”. This is the folder that contains all the other folders that the operating system uses. Other filesystems are mounted onto the root filesystem to be used.

Right, as to why it might need expanding. If you remember we installed a disk image, which is a byte for byte copy of another disk. Now what happens if your image is smaller than the disk you are copying it onto? Well the extra space is just left empty. So this option will take the root filesystem and grow it till it fills any extra empty space on your disk. Do you want it to do this? Almost certainly yes. The other option is that you format this unused space to create a new partition with its own filesystem on it and mount it onto the root filesystem, but I struggle to think up a good reason why anyone would (though there is undoubtedly some unusual use case where this is good idea). So go ahead, select it and hit enter. Some text will flash by, and it’ll tell you that the filesystem will be expanded on the next boot.

Overscan

Overscan is a way of making sure the picture fills all of the screen when using an old TV as a monitor. This won’t affect anything when connecting to the pi over the network, as we are now, but if it is likely that at some point in the future the pi will be attached to an old TV using the composite out, turn it on (you will also need to tweak the actual amount of overscan needed for your TV); if it is more likely to connected to a modern LCD TV turn it off; if you’re not likely to do either, just skip over it.

Configure Keyboard

This won’t do anything at the moment, as we don’t have a keyboard physically connected to the pi. So you can just skip it. In case you wondered, different keyboards have different layouts and keys on them (most commonly this is to incorporate letters and symbols that aren’t commonly used in other languages). The default for the pi is the standard British keyboard. If, at a later date, you do want to plug in a keyboard, if it isn’t a stand British keyboard, you will have to configure it (there are various ways of doing so, but just firing up raspi-config again is pretty reasonable way of doing it).

Change Password

This is probably the most important option! All Raspberry Pies have the same default password so you really need to change this, else everyone and their dog will be able to log on to it. Make sure you can remember it though, else you’ll have to wipe the disk and start again!

Change Locale

The locale is a specific combination of language and regional differences. For example, though the UK and the US share the same language, English, there are many regional differences e.g. in the UK the first of February is referred to as 01/02/13 but in America it is referred to as 02/01/13. The locale setting is how the pi works out how to translate its output for you.

The pi uses the standard POSIX locale codes, which start with the language and then the region e.g. for British English it is en_GB (English, Great Britain) and for American English it is en_US (English, United States). The default for the pi is en_GB. If this isn’t for you, choose your locale from the list (you want the UTF8 version). If you are multilingual, you can have multiple locales installed and switch between them; if you aren’t multilingual, then deselect any you don’t need. Changing the locale settings may take a short while.

Change Time Zone

This pretty much self explanatory. The pi defaults to London for the time zone (GMT 0) if you live somewhere else, set the time zone appropriately.

Memory Split

The pi has one chunk of memory which it shares between the main processor and the graphics processor. If you don’t intend to attach a monitor anytime soon, you aren’t really going to be using the graphics processor, so you can give your pi a nice little speed up by giving as much of the memory as possible to the main processor, so set it to 16. If you do intend to use a monitor soon, then you can set the split up now or just re run raspi-config later. For a general purpose desktop, setting it at 128 is probably a good start (if you have an older pi that only has 256MB of memory, you might want to set the graphics chip to only have 64MB and sacrifice the ability to play hi-res video files).

Overclock

Overclocking is the process of running a computer faster than it is specified. Due to variances in the manufacturing process, it isn’t possible to tell how much your processor can be overclocked (if at all) before the system becomes unstable, so if you do want to try, the best thing to do is to gradually increase the amount of overclocking. Overclocking will increase the amount of heat generated by the processor, and so will reduce its working life. If it is worth overclocking, largely depends on what you want to use the pi for. For most people, overclocking a modest amount is perfectly safe, but if you don’t need that extra processing power, then there isn’t any point in risking damaging the pi. If you want to really crank up the overclocking, you will probably need to invest in some sort of cooling for the processor.

ssh

You are almost certainly going to want to leave this at its default of enabled!

Boot Behaviour

As we are using the pi without a monitor, you defiantly want to leave this at its default of not starting the graphical login when it is turned on. Starting up the graphics system will take up a lot of unnecessary resources.

And that is it, we’re done. Press tab, move over to the finish button and press enter.

You now need to restart your pi so that the root file system can be expanded and that any change to memory split can take effect. To do that type:

sudo shutdown -r now

The computer will then restart and you’ll be disconnected from it. Give it a minute to expand the filesystem, and then reconnect to it again with ssh. It will almost certainly have the same ip address as before, but if your network is really busy with computers connecting and disconnecting all the time there is a (really) small chance some else will have taken that ip address and you’ll have to search for the pi’s new one as you did before.

Anyway, once you are at the log in prompt, enter your ***new*** password and tadaa! You’ve successfully completed the basic setup of your raspberry pi without the need for plugging in a keyboard or monitor! Give yourself a pat on the back.

Now it needs to be configured for what ever task you have in mind for it. Check out my up coming posts on how to configure to be a file server, media centre and much more! Hope you’ve had fun and learned a thing or two!