← System admin on a Raspberry Pi

Log in to the Pi from your laptop

A Raspberry Pi can run with no screen. From your laptop you reach it by name or address and type to it with ssh. Every command after ssh runs on the Pi, until you type exit.

The Pi has no screen on it. How do you control it from across the room?

A server is a computer you run from somewhere else. Almost every server, and every Pi without a screen, is run by typing to it over the network. This is the same idea as Across the internet in Networks: names and addresses find the computer, then messages go to it.

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

Where does it run?

On your laptop you type ssh pi@raspberrypi.local and log in. Where does the next command you type run?

TryTry it on the board and compare the result with your prediction.

Try: reach the Pi

Was your prediction right?

Try it yourselfYour edits are saved in this browser.

Log in with ssh pi@raspberrypi.local. Look at the prompt: whose name is in it now?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: Logging in, step by step

Worked exampleBefore each step, say what you think comes next.
  1. ssh pi@raspberrypi.local\text{ssh pi@raspberrypi.local}user pi, computer raspberrypi.local. ssh is the program that joins you to it.

Now try it yourself.

The Pi is reachable as raspberrypi.local and as 192.168.1.23. After the router restarts, which is more likely to still work?

Sam checks the Pi's disk space. Click the line where it first goes wrong.

ssh pi@raspberrypi.local says: Connection refused. What does it most likely mean?

ModifyChange the problem on purpose and see what happens.

Vary: change one thing

Try it yourselfYour edits are saved in this browser.

Log in, then run hostname to ask the Pi its name.

Use the board. This ticks when you get there.

You are on the Pi. Check that it can reach your laptop at 192.168.1.20 with ping.

Use the board. This ticks when you get there.

Try ssh sam@raspberrypi.local. The Pi has no user sam. What happens?

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Practise

Which of these cannot be an IP address?

You are logged in to the Pi over ssh. You type exit. Where are you?

Review: a file is rw------- (600). Can another user read it?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Check in on the Pi

Then: on a real Pi (or any Mac or Linux computer) try hostname and uptime.

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

You need to be on the Pi first.

Another hint

ssh pi@raspberrypi.local

Another hint

Then type uptime.

From your laptop, log in to the Pi and run uptime to see how long it has been on.

Use the board. This ticks when you get there.

Now you can
Next lesson2. Install software with aptOn a Pi you add programs with apt, from a software source on the internet. You update the lists first, then install. sudo runs one command as the administrator, and the system records who used it.
For teachers

A Raspberry Pi can run with no screen. From your laptop you reach it by name or address and type to it with ssh. Every command after ssh runs on the Pi, until you type exit. About 40 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the boards yourself.

The one idea: ssh joins your keyboard to another computer, so commands run there. Names and addresses find a computer (Networks › Across the internet); an account says who may use it (Security and privacy).

Simplifications: the pretend laptop knows one Pi, raspberrypi.local or 192.168.1.23, and its password is always accepted. A real Pi asks for the password you set.

Real Pi (optional, any time): the pretend Pi is the same for every student, so nothing here needs hardware. If you have Pis, any number per group works, Pi 4 or Pi 5. A Pi 5 needs a 27 W USB-C supply (a 15 W phone charger makes it complain and limit USB power). Students can sit at a Pi with a screen and keyboard, or reach it by ssh from a laptop once it is on the network. Either start works for every lesson after the first: choose a ready-made image (you set the hostname, the user and ssh once, then clone the card) or have students flash their own with Raspberry Pi Imager (OS: Raspberry Pi OS Lite 64-bit; in the settings set a hostname, a user and password, ssh on, and Wi-Fi if needed). Both reach lesson 2 in the same state. To start again: reflash the card, or write a short reset script (remove added users, sudo apt remove, restore saved config files) and run it.

Other options: this lesson uses ssh, which is on Mac, Linux and recent Windows. On older Windows, PuTTY does the same job. A Pi with a screen and keyboard needs no ssh at all; the next lessons are identical.

Running the lesson

  1. Predict: the wrong answers think the laptop does the work.
  2. Try: ask whose prompt it is.
  3. Worked example: point out how little changes on screen, but everything changes where it runs.
  4. Vary: ask why a wrong user is refused even though the Pi is reachable.
  5. Make: ask what an administrator checks first when a server seems slow.

The hard part (on purpose)

Students forget which computer they are typing on. Read the prompt aloud every time: sam@laptop or pi@raspberrypi.

When students get stuck

Stretch and support

Stretch: Find out what ssh keys are and why many servers do not allow passwords at all.

Support: Write the two prompts on the board: sam@laptop and pi@raspberrypi.

Where it leads

Links: Networks › Across the internet (names and addresses); Security and privacy › Names and addresses; next: Install software.

What each step is for