
Recall first from From board to first boot
- A Raspberry Pi is a single-board computer around a Broadcom SoC; the microSD card holds everything it boots from.
- Headless means no monitor or keyboard: enable SSH with a marker file and supply Wi-Fi with a config file.
- Verify the downloaded image checksum before flashing: a corrupted image or a bad write boots to a silent failure.
SSH first contact
3 min readThe board is now flashed and booting headless, so it is reachable on your network. This lesson answers how to reach it over SSH with key authentication and when to fall back to the serial console.
Connect with ssh, giving the user and the board's address:
ssh learner@sensorpi.local
On the very first connection, the server presents its a long-term public key that identifies one specific SSH server, and the client shows a fingerprint of it. Typical output looks like this (yours will differ):
The authenticity of host 'sensorpi.local (192.168.1.42)' can't be established.
ED25519 key fingerprint is SHA256:AbC... (yours will differ).
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Answering yes stores the key in ~/.ssh/known_hosts. From then on the client checks that the server presents the same key, so that a machine impersonating your board cannot silently take over the connection.
That same check explains a warning you will meet one day: if the key changes, ssh refuses to connect and prints a message like REMOTE HOST IDENTIFICATION HAS CHANGED. That happens when you reflash the OS, which gives the board a new host key, or when a new device takes over an old IP address. If the change is expected, remove the stale entry with ssh-keygen -R and reconnect:
ssh-keygen -R sensorpi.local
SSH also uses a two related keys: a public key you can share freely and a private key you keep secret. Right now you are logging in with the password you set during setup, but the better way is to authenticate with your own key, which the next section covers.
Treat the changed-key warning as meaningful. If you did not reflash the board or change its address, investigate before answering yes to a new fingerprint.
SSH key authentication, done right
4 min readGenerate a key pair on your laptop with ssh-keygen. Ed25519 is the recommended type:
ssh-keygen -t ed25519 -C "learner@labpc"
The command writes a private key to ~/.ssh/id_ed25519 and a public key to ~/.ssh/id_ed25519.pub. The public key is safe to copy anywhere; the private key must stay on your machine and readable only by you, which connects back to the permissions work in the previous lesson:
chmod 600 ~/.ssh/id_ed25519
Toggle the bits below to see which mode is owner-only (600):
Install the public key onto the board with ssh-copy-id, which asks for your password once and then appends the key to the board's ~/.ssh/authorized_keys file:
ssh-copy-id learner@sensorpi.local
From now on ssh authenticates you with the key. The mechanism is a signature, not an encryption: the server sends a random challenge, the client signs it with the private key, and the server verifies the signature against the public key in authorized_keys. This is the SSH-2 design described in RFC 4252. Ed25519 is a signature-only algorithm, so the older idea of the server encrypting a challenge with your public key does not apply to it.
Request: the client asks to authenticate and sends the public key it wants to use.
Challenge: the server checks that the key is in authorized_keys, then sends random data.
Signature: the client signs the challenge with its private key, which never leaves the client.
Verify: the server verifies the signature using the stored public key.
Grant: a valid signature proves possession of the private key, so the server allows the login.
Once key login works, disable password authentication so that only key holders can get in. Edit /etc/ssh/sshd_config on the board and set:
PasswordAuthentication no
then restart the server:
sudo systemctl restart ssh
Open a second SSH session and confirm key login works in it before you disable passwords, and keep the first session open while you do. Disabling password auth before you have a working key can lock you out of a headless board.
Going deeperWhy Ed25519, and why the private key permissions matter
Ed25519 is a modern elliptic-curve signature scheme that OpenSSH generates by default. It is fast, small, and signature-only, which is why the SSH-1 style of encrypting a challenge with the public key simply does not exist for it. RSA keys are still common, and they too authenticate by signing in SSH-2. The ~/.ssh directory and the private key must not be writable by others, or the server and client both refuse to use them; this is the same least-privilege principle from the permissions lesson, applied to a credential rather than a document.
The serial console and GPIO numbering
3 min readA universal asynchronous receiver/transmitter, the hardware that moves bytes one at a time over a transmit and a receive wire on the Pi is exposed on the GPIO header. Transmit is GPIO14 on physical pin 8, receive is GPIO15 on physical pin 10, and ground is pin 6. The trick is to cross the wires: your adapter's TXD wire goes to the Pi's RXD (pin 10), and the adapter's RXD wire goes to the Pi's TXD (pin 8). Ground connects to ground.
The signal is 3.3 V TTL, not the 12 V of old PC serial ports, so you need a USB-to-serial adapter that speaks 3.3 V logic (FTDI, CP2102 or CH340 based boards all work). Leave the adapter's power pin unconnected: the Pi is already powered.
Open the console with a terminal program at 115200 baud, 8 data bits, no parity, one stop bit, written 115200 8N1:
sudo apt install picocom
picocom -b 115200 /dev/ttyUSB0
screen and minicom are equivalent alternatives: screen /dev/ttyUSB0 115200 or minicom -D /dev/ttyUSB0 -b 115200. On the Pi, the UART may need enabling first. On a Pi 4 the primary UART is wired to Bluetooth by default, so add this line to config.txt:
enable_uart=1
On a Pi 5 the GPIO14/15 UART is enabled with a device-tree parameter instead:
dtparam=uart0_console
The Pi 5 also has a dedicated 3-pin debug UART connector that is active by default, so on that model you can attach a lead there without any config change. On Pi 1, 2 and 3 the UART on GPIO14/15 is the primary console already. The raspi-config menu (Interface Options, then Serial) writes the same setting for you.
For the kernel to actually print to the serial port, the cmdline.txt file must name it:
console=serial0,115200 console=tty1 root=PARTUUID=xxxxxxxx-02 rootfstype=ext4 fsck.repair=yes rootwait
The console=serial0,115200 part tells the kernel to send its boot messages to the UART at 115200 baud, which is how you capture the boot log even when nothing else works.
TXD must reach RXD, not TXD. And never feed 5 V or RS-232 levels into these pins; both can damage the SoC.
learner@embeddex:~/lab$ # on a Pi 4, enable_uart=1 turns on the GPIO14/15 UART learner@embeddex:~/lab$ printf 'enable_uart=1\n' > config.txt && cat config.txt enable_uart=1 learner@embeddex:~/lab$ # on a Pi 5 the same UART is enabled with a device-tree parameter learner@embeddex:~/lab$ printf 'dtparam=uart0_console\n' > config.txt && cat config.txt dtparam=uart0_console learner@embeddex:~/lab$ # cmdline.txt must name the UART at 115200 for the kernel to print boot logs to it learner@embeddex:~/lab$ printf 'console=serial0,115200 console=tty1 root=PARTUUID=xxxxxxxx-02 ro otfstype=ext4 fsck.repair=yes rootwait\n' > cmdline.txt && cat cmdline.txt console=serial0,115200 console=tty1 root=PARTUUID=xxxxxxxx-02 rootfstype=ext4 fsck.repair=yes ro otwait
Key takeaways
- SSH proves identity with a key pair; the client signs a challenge with its private key and the server checks the public key.
- The serial console is a 3.3 V UART on GPIO14 and GPIO15 at 115200 8N1, opened with picocom or screen.
- The host key identifies one specific SSH server; a changed key after a reflash is fixed with ssh-keygen -R, and an unexpected change must be investigated.
- Cross the UART wires: the adapter's TXD goes to the Pi's RXD (pin 10) and its RXD to the Pi's TXD (pin 8).
Reflect
- Explain to a colleague, in two sentences: connect over SSH, interpret the host-key prompt, and install a key with ssh-copy-id.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Official docsOpenSSH
- SpecificationRFC 4252 - SSH Authentication Protocol
- Man pagessh(1) manual page
- Man pagesshd_config(5) manual page
Official documentation first. Links checked when the lesson was published.