Raspberry Pi - What to do after first boot

raspberrypi hacking
9 minutes to read
October 16, 2018

When you boot into your Raspberry Pi for the first time, it’s ready to do wonders! But before you do so, you can/should do some adjustments to better manage it.

Over the years, I’ve setup many Pis and here are the things I perform when I first boot into one.

Before we get started:

[mandatory] Start logging

Alright, first things first. Good practices at all times! Therefore keep a log of what you’ve done with your Pi.

You might see your Pi as a spare time hobby thing but chances are you are going to setup another Pi in the future or you are going to use the procedures you’ve accomplished on this Pi in another Linux project of yours; since, you know, Linux is everywhere.

As time goes by, you’ll forget what you’ve configured; especially the minor ones. Also there is good chance that you’re going to deal with stuff that weren’t exactly hard to accomplish but just hard to figure out what to do and it pays to know what you did so that a ten minute configuration doesn’t prolong for hours of research. So, be a good lad or gal, and write down exactly what you’ve configured. Nothing fancy: just a few words and a link to the tutorial if there is one should be sufficient.

If you want a template, you can grab mine. I’ve also added some dummy content to get you started.

Raspberry Pi Log Sample

[mandatory] Change the default password

That should be the very first thing you do when you first boot into your Pi.

Just type passwd and change your Pi’s default password to anything else other than raspberry.

Pis are mostly installed in homes to do some hacking on the side so you might be the only one to tinker with it but as a good practice, just do it.

[mandatory] Assign a static IP

Since you’ll be remotely interacting with your Pi, it’ll need a static IP. Otherwise you may have to fish it out every time your Pi boots or your network restarts.

To do so, I would like to point you to this good resource.

[mandatory] Update the system

Before you go any further, update your Pi to keep it at it’s best.

Even if you’ve just downloaded Raspbian, it will have some outdated packages lying inside.

1
apt-get update && sudo apt-get upgrade && sudo apt-get clean

[mandatory] Clone the SD Card

I can’t emphasise this enough! Once you’ve configured your Pi to your needs, you MUST clone the SD card.

By cloning the SD card, you’ll have a re-usable image. Exactly like the Raspbian image you’ve downloaded but with all the software you’ve installed and the configurations you’ve made.

Therefore, if something goes wrong with your Pi(and chances are that it will), you can easily carry on with the clone you’ve made rather than a clean slate.

Depending on when you’ve made your clone, you might have some inconsistencies with your last working Pi state, but trust me, if you’ve made a lot with your Pi, like me, it’s much better to deal with minor inconsistencies than major ones; like a fresh copy of Raspbian. :]

One more thing before we start. The clone you’ll be making will be the size of your SD card even though you’re not using all of it’s capacity. Therefore the cloned image of a 32GB SD card will take up 32 GB of space on your computer.

In order to create a clone of your Pi:

The amount of time consumed by the cloning operation will depend on your Macs speed and your SD cards size.

And the bummer is that, there is no progress bar during the operation. So, be patient and let the process run its course.

For instance, the clone I’ve made on my 2017 MBP(2.8 GHz i7 with 16 GB RAM) took roughly 70 minutes.

In order to restore your clone:

Again, the above process will also take quite a bit of time depending on your Macs speed and the images size; and there is no progress bar again. So be patient.

One last thing to mention about cloning is to repeat from time to time. Your Pi is not a mission critical thing, so it doesn’t need to be cloned in a tight manner but a clone every a few months should do it.

[optional] Install vim

Raspbian doesn’t come with vim pre-installed which is the editor I prefer.

1
apt-get install vim

Also, from this point on, I will be explaining file edits via Vim. If you choose not do so, go with your preferred text editor.

[optional] Create a custom user

I can’t think of a mandatory technical reason for this one but in order to keep things neat and tidy, I prefer to create a new user account to work on the Pi.

To create a new user, simply execute the following command:

1
adduser [USERNAME]

If you would like to give that newly created user sudo privileges, follow the steps below. However, you’ll be editing a system file with the system’s default text editor, which is currently set to nano. If you prefer vim like I do, execute the following command beforehand:

1
update-alternatives --set editor /usr/bin/vim.tiny

On to giving sudo privileges to your newly created user:

And now take your newly created user’s sudo privileges for a spin:

Remark

I would suggest you not to delete the user pi since some software makes use of it!

[optional] Password-less login

It’s more secure and convenient to login with public-key authentication.

First make sure that you’re logged in as your newly created user. Afterwards:

1
2
3
4
5
cd ~
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

Then on your local machine:

1
2
cd ~/.ssh
ssh-keygen -t rsa -b 4096

Follow the on-screen instructions.

Once done, copy the contents of the newly created key’s public part and paste it into the authorized_keys file on your Pi. For example, on macOS, to copy the contents:

1
cat [KEY_NAME].pub | pbcopy

[optional] Adjust your SSH defaults

Let’s do some basic adjustments to how sshd functions. This will be a quick recap and if you want more detail on what relates to what, do search the web or checkout the resources down below.

First, open the file that holds the configuration for sshd:

1
vim /etc/ssh/sshd_config

Afterwards, change the following parameters in the file as suggested below:

1
2
3
4
5
6
7
8
9
- AuthenticationMethods publickey
- PubkeyAuthentication yes
- PermitEmptyPasswords no
- Port [YOUR_DESIRED_PORT NUMBER]
- ClientAliveInterval 300
- ClientAliveCountMax 0
- Banner /etc/issue
- IgnoreRhosts yes
- HostbasedAuthentication no

Once you’re done, have sshd acknowledge the changes by restarting it:

1
service ssh restart

Remark

About port number designations:

[optional] Install ZSH

Bash is a great shell, although I prefer to work with Zshell(zsh) because it’s much more capable:

Hence, to install it and make it your default:

1
2
apt-get install zsh
chsh -s $(which zsh)

[optional] Change it’s hostname

If you (will) have multiple Pis on your network or just want to differentiate your single Pi’s name, you should change it’s hostname.

For the hostname, you can only use:

There are two files managing the hostname of your Pi. For the first one:

1
vim /etc/hostname

It should only contain a name, so change it to whatever you like.

For the second file(which is only there for some software):

1
vim /etc/hosts

Find the line starting with 127.0.0.1 and change the hostname to your preferred one.

Ideas

Now that your Pi’s got the fundamentals, the world is yours! 😜

You can do a lot with a Pi but here are some everyday ideas to make it useful in your home environment:

Remark

For the purposes of turning your Pi into a media center, you’ve a few options out there other than Kodi; such as OpenElec(formerly XMBC) or OSMC(successor to Raspbmc). But those are separate operating systems built on top of other OSs. Meaning that if you choose one of them your Pi will serve merely as a media center and nothing else!

Personally, I prefer to go with the combination of Raspbian and Kodi since it allows me to do other things. Your preference may differ.

You can also go with the path of installing Raspbian on an SD card and OpenElec or OSMC on another and swap them out when needed, however, that’s nowhere near convenient.

If you want some more information on turning a Pi hardware into a media center, here is a good resource.

Resources

under construction...