← Teacher guide

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.

System admin on a Raspberry Pi · Set up · about 40 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min

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.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

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

What you will seeA question to askThe fix
A student runs commands and nothing seems to change.Whose prompt is it? Have you logged in?ssh pi@raspberrypi.local first.
A student types exit and thinks the Pi has shut down.What did exit end?Only the session. The Pi keeps running.

Answers to the checks

  1. where does it run?: On your laptop you type ssh pi@raspberrypi.local and log in. Where does the next command you type run?
    On the Pi. Until you type exit, everything you type is sent to the Pi and run there. Only the text comes back.
  2. Try: reach the Pi: Log in with ssh pi@raspberrypi.local. Look at the prompt: whose name is in it now?

    The prompt says pi@raspberrypi. You are typing on your laptop, but the commands run on the Pi.
  3. Logging in, step by step: The Pi is reachable as raspberrypi.local and as 192.168.1.23. After the router restarts, which is more likely to still work?
    raspberrypi.local: the name follows the Pi
    The name goes with the Pi. The router may give it a new address, so use the name first and the address as a backup.
  4. Find the mistake: Sam checks the Pi's disk space. Click the line where it first goes wrong.
    line 2
    Line 2: without ssh, df -h shows the laptop's disk. Log in with ssh first, then the command runs on the Pi.
  5. Connection refused: ssh pi@raspberrypi.local says: Connection refused. What does it most likely mean?
    Nothing on the Pi is listening for ssh
    Refused means the Pi is on the network and answered, but no program is waiting on port 22 (the ssh service is stopped). Services come in lesson 4.
  6. Ask its name: Log in, then run hostname to ask the Pi its name.

    ssh pi@raspberrypi.local, then hostname prints raspberrypi.
  7. Can it reach the laptop?: You are on the Pi. Check that it can reach your laptop at 192.168.1.20 with ping.

    ping 192.168.1.20: replies mean the two computers can talk.
  8. No account: Try ssh sam@raspberrypi.local. The Pi has no user sam. What happens?

    Permission denied: you need an account on the Pi. Names and addresses find a computer; accounts decide who may use it.
  9. Address check: Which of these cannot be an IP address?
    192.168.1.300
    Each number is 0 to 255, so 300 is too big.
  10. Leaving: You are logged in to the Pi over ssh. You type exit. Where are you?
    Back at your laptop's prompt
    exit closes the ssh session. The Pi keeps running.
  11. Review: permissions: Review: a file is rw------- (600). Can another user read it?
    No: others have no permissions
    The last three characters are ---: nothing for everyone else.
  12. check in on the Pi: From your laptop, log in to the Pi and run uptime to see how long it has been on.

    uptime tells you how long the Pi has been on. Administrators check it first when something seems wrong.

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: change one thing › Ask its name

Open task: any program that does what the step asks.

Vary: change one thing › Can it reach the laptop?

Open task: any program that does what the step asks.

Vary: change one thing › No account

Open task: any program that does what the step asks.

check in on the Pi

Open task: any program that does what the step asks.

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.

Exit ticket

Where does a command run after you ssh to the Pi, and how do you get back?

On the Pi. Type exit to return to your laptop.

What each step is for

Where it leads

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