Homelab

JPNAS.NET / Homelab

Chapter 2 · Part A – The server – foundationLast updated:

Unlocking the Encrypted Disk over SSH after a Reboot (dropbear)

A small SSH server inside the initramfs lets you type the disk passphrase from another computer, so an encrypted server can restart – even after a power cut – without a monitor and keyboard.

Back to the network map and all chapters

What You Need
Debian 13 with an encrypted system disk (LUKS + LVM) from chapter 1
An ed25519 SSH key on the computer you already use to log in to the server (its public key is in ~/.ssh/authorized_keys on the server)
A fixed address for the server from a DHCP reservation in the router (chapter 1.11)
Once, for the BIOS settings in step 2.8: a monitor and a keyboard

Jump to the Summary

The problem: the system disk is encrypted (chapter 1). At every start – also after a power cut – the server stops and waits for the passphrase. Without a monitor and keyboard next to it, it would simply stay there.

The solution: add a tiny SSH server, dropbear, to the initramfs – the small system that runs before the disk is unlocked. From another computer you connect to it, type the passphrase, and the server continues booting.

As in chapter 1, every step has the same shape: Command – what you type, What it does – the explanation, and Check – how you know it worked. The names are examples; use your own.

Example names used in this chapter:

WhatExample
Server namehomeserver
Fixed address192.168.40.20
Port for unlocking2222
SSH shortcut for unlockingunlock-homeserver

How It Works

power on → BIOS → GRUB → kernel + initramfs (from the unencrypted /boot)
                          │
                          ├─ network (DHCP)  → gets 192.168.40.20
                          ├─ dropbear on port 2222 (keys only)
                          └─ waits for the LUKS passphrase ◄── ssh -p 2222 root@192.168.40.20
                                     │
                     passphrase correct → disk unlocked → Debian starts → OpenSSH on port 22

Dropbear runs only until the disk is unlocked. Once the system is up it is gone, and the normal OpenSSH server on port 22 takes over.

2.1 Install dropbear-initramfs

Command:

sudo apt install -y dropbear-initramfs

What it does: installs dropbear and the scripts that build it into the initramfs – again after every kernel update.

Check:

ls /etc/dropbear/initramfs/

The list contains dropbear.conf and the host keys (dropbear_ed25519_host_key and others). During the installation it may warn that there are no authorized keys yet – that's the next step.

2.2 The Allowed Keys

Command:

sudo cp ~/.ssh/authorized_keys /etc/dropbear/initramfs/authorized_keys
sudo chmod 600 /etc/dropbear/initramfs/authorized_keys

What it does: gives dropbear the same public keys you use to log in to the system. Only devices with these keys can unlock the disk.

Check:

sudo wc -l /etc/dropbear/initramfs/authorized_keys

The number of lines is the number of your devices (for example 2: a Windows laptop and a Linux desktop).

When you add a new device later (a phone, say), add its public key to both files – ~/.ssh/authorized_keys and this one – and repeat step 2.4.

2.3 Dropbear Options

Command:

echo 'DROPBEAR_OPTIONS="-p 2222 -s -j -k -c cryptroot-unlock"' | sudo tee -a /etc/dropbear/initramfs/dropbear.conf

What it does: sets the options dropbear starts with (see man dropbear):

OptionMeaning
-p 2222listens on port 2222, not 22 – so the client never mixes dropbear's host key up with the OpenSSH one
-sno password logins, keys only
-j -kno local or remote port forwarding
-c cryptroot-unlockafter login only the passphrase prompt runs – no shell, whatever the client asks for

Check:

grep DROPBEAR_OPTIONS /etc/dropbear/initramfs/dropbear.conf

shows exactly one uncommented line with these options.

2.4 Rebuild the initramfs

Command:

sudo update-initramfs -u -k all

What it does: builds a new initramfs for every installed kernel, now with dropbear, the keys and the options inside.

Check:

sudo lsinitramfs /boot/initrd.img-$(uname -r) | grep -E 'dropbear|authorized_keys'

sudo is needed: the initramfs can only be read by root, because it contains dropbear's private host keys. The output looks like this:

etc/dropbear/dropbear.conf
etc/dropbear/dropbear_ecdsa_host_key
etc/dropbear/dropbear_ed25519_host_key
etc/dropbear/dropbear_rsa_host_key
root-XXXXXXXXXX/.ssh/authorized_keys
scripts/init-bottom/dropbear
scripts/init-premount/dropbear
usr/sbin/dropbear

Inside the initramfs root's home folder gets a random name (root- and ten characters), so the path is different on every server. What matters is that …/.ssh/authorized_keys is there. If it's missing, dropbear doesn't know your key and remote unlocking won't work.

After a kernel update, check the new kernel's initramfs before rebooting (for example sudo lsinitramfs /boot/initrd.img-<new-version> | grep authorized_keys), not the one that is running now. Normally there is nothing to do: Debian rebuilds the initramfs after every kernel update by itself and dropbear stays in. By hand you only need update-initramfs after changing the keys or the options.

2.5 A Shortcut on Your Computer (Windows or Linux)

Dropbear has its own host key, different from OpenSSH's. If you connected to the same address under the same name, SSH would warn "REMOTE HOST IDENTIFICATION HAS CHANGED". So unlocking gets a name of its own.

Command: add this to C:\Users\<name>\.ssh\config (Windows) or ~/.ssh/config (Linux, macOS):

Host unlock-homeserver
    HostName 192.168.40.20
    Port 2222
    User root
    IdentityFile ~/.ssh/id_ed25519

What it does: ssh unlock-homeserver now connects to dropbear on port 2222 as root with your key. Because the port is different, dropbear's host key is remembered separately from the OpenSSH one.

Check: at the next reboot (step 2.6).

2.6 The Test

Command (on the server):

sudo reboot

Wait about 30–60 seconds for the BIOS, GRUB and the network in the initramfs.

Command (on your computer):

ssh unlock-homeserver

The first time, confirm dropbear's host key with yes. Then you see:

Please unlock disk nvme0n1p3_crypt:

Type the disk passphrase and press Enter. Nothing is shown while you type.

What it does: the passphrase goes to the initramfs scripts, which unlock the disk; the connection closes (Connection closed) and the system boots.

Check (after about 20 seconds):

ssh homeserver
uptime

The server has been up for only a few dozen seconds.

If the passphrase is rejected, type it. Pasting from a password manager can work for a while and then suddenly fail with bad password or options?, while the same passphrase typed by hand works at once. After three wrong attempts the prompt gives up and closes the connection. The disk stays locked and nothing breaks – simply run ssh unlock-homeserver again. If it no longer connects at all, switch the server off by holding the power button for about five seconds and switch it on again; that is safe, because before unlocking no disk is mounted.

2.7 From Outside – Only through the VPN

Port 2222 is not forwarded on the router. From outside the house you first connect to the home VPN (chapter 8 – WireGuard), and then ssh unlock-homeserver works exactly as at home.

Why not public: the dropbear inside the initramfs is a separate, minimal program that only gets updated when the initramfs is rebuilt – there is no reason to show it to the whole Internet.

2.8 Automatic Start after a Power Cut, and a Locked BIOS

For this you need a monitor and a keyboard one more time (keyboard on a rear USB port). Menu names differ between makers; on a Lenovo ThinkCentre, for example, you press F1 at power-on.

SettingValueWhy
Power → After Power LossPower Onafter a power cut the server switches itself on and waits in the initramfs for the passphrase
Security → Administrator Passwordset (keep it in the password manager)nobody can change the BIOS settings without it
Security → Power-On Passwordnot setotherwise the server would wait for a password already in the BIOS and never start by itself
Security → Smart USB ProtectionNo AccessUSB sticks and disks stop working, keyboard and mouse still work
Devices → USB Setup → Front USB PortsDisabledthe rear ports stay on – without a keyboard you couldn't get into the BIOS any more
Security → Require Admin. Pass. for F12 BootYesbooting from another disk or from the network only with the password

Save with F10 → Yes.

With Smart USB Protection on No Access you can no longer start an installation from a USB stick (chapter 1.2). For a reinstall, switch it off temporarily – that's what the BIOS password is for.

Check: pull the server's power plug and put it back (or wait for the next power cut). The server switches on by itself, and after 30–60 seconds ssh unlock-homeserver (at home or through the VPN) shows Please unlock disk ….

What This Means for Security

AspectState
Someone steals the server or the diskthe data stays encrypted – without the passphrase there is nothing to read
Logging in to dropbearkeys only, no passwords, no shell (-c cryptroot-unlock)
Who can reach port 2222only the admin network and the VPN – the firewall on the router blocks it from the guest, family and IoT networks (chapter 7)
The limit/boot with the initramfs is not encrypted. Someone with physical access who can change it (an "evil maid" attack) could in theory slip in a modified initramfs that records the passphrase. The defence: a BIOS password, locked USB ports and no booting from other devices (step 2.8), and the server in a place where strangers don't get to it.

Why the host keys of dropbear and OpenSSH should be different: dropbear's keys live in the unencrypted initramfs, so anyone with the disk could copy them. If OpenSSH used the same keys, they could pretend to be your server even after it has booted. The Debian package therefore generates separate keys – leave it that way.

Summary

WhatState
Programdropbear-initramfs
Port2222 (only the admin network and the VPN)
Loginroot with an ed25519 key, no password
After loginonly cryptroot-unlock
Shortcutssh unlock-homeserver
After changing keys or optionssudo update-initramfs -u -k all
After a power cutstarts by itself, waits for the passphrase

Next: Chapter 3 – Hardening: SSH keys only, ufw, fail2ban. For how the disk encryption itself works, see How Encryption Works.