A Drop Bear Before Boot: Unlocking LUKS over SSH on Ubuntu 26.04 Source
Markdown source
1---2title: "A Drop Bear Before Boot: Unlocking LUKS over SSH on Ubuntu 26.04"3date: "2026-08-03"4published: true5tags: ["linux", "ubuntu", "ssh", "dropbear", "luks", "encryption", "security", "initramfs"]6author: "Gavin Jackson"7excerpt: "My encrypted server was secure right up until it rebooted and waited for a passphrase nobody could type remotely. Dropbear gave me a tiny SSH server inside the initramfs and a safe way to unlock LUKS from elsewhere."8---910# A Drop Bear Before Boot: Unlocking LUKS over SSH on Ubuntu 26.041112<p align="center"><img src="/assets/dropbear-ssh/dropbear-luks-server.png" alt="An evil-looking drop bear guarding a locked server rack in a dark data centre" width="1600"></p>1314*The drop bear guarding the server is fictional. The problem it is guarding against is not.*1516Full-disk encryption on a server creates an awkward little contradiction.1718I wanted the root volume encrypted with LUKS so that taking the disks, or the whole machine, did not also mean taking the data. That worked exactly as intended. It also meant that every reboot stopped at the early boot prompt waiting for somebody to enter the LUKS passphrase.1920That is fine when the server is under a desk. It is less fine when it is headless, remote or simply on the other side of a locked door.2122My answer was **Dropbear**, a compact SSH server small enough to run from the initramfs. It brings up the network before the encrypted root filesystem is mounted, accepts a key-authenticated SSH connection and lets me run `cryptroot-unlock`. Once I enter the LUKS passphrase, the real root filesystem opens and Ubuntu continues booting normally.2324This article shows the setup I used on Ubuntu Server 26.04 LTS. It assumes the root volume is already encrypted with LUKS and the machine uses Ubuntu's usual `initramfs-tools` boot path.2526> Do not make your first test on a remote machine without working console access. A typo in early-boot networking can turn a routine reboot into a drive to the server.2728## What Dropbear actually is2930[Dropbear](https://matt.ucc.asn.au/dropbear/dropbear.html) is a small SSH 2 server and client written for constrained Unix-like systems. It supports OpenSSH public keys, can run as a standalone daemon and can be compiled with unwanted features removed. Its small dependency and memory footprint made it popular on routers and embedded Linux, but the same qualities also make it a very good fit for an initramfs.3132There is an Australian connection beyond the name. Dropbear's author is **[Matt Johnston](https://github.com/mkj)**, an Australian developer based in Perth whose site is hosted by the University Computer Club at the University of Western Australia. The name is a nod to the Australian drop bear: the allegedly vicious cousin of the koala that Australians warn visitors about with an entirely straight face.3334On Ubuntu, `dropbear-initramfs` does not replace the normal OpenSSH server. It installs the pieces needed to build a separate, temporary Dropbear environment into the initramfs. Ubuntu 26.04 packages Dropbear 2025.89 for this purpose in the `universe` repository.3536## Why the normal SSH server cannot help3738When an encrypted-root machine first starts, most of the operating system is still behind LUKS. `/etc/ssh`, user accounts, systemd units, firewall rules and the normal OpenSSH daemon are all sitting inside a filesystem the kernel cannot read yet.3940The initramfs is different. It is a small temporary filesystem loaded into memory alongside the kernel. It contains just enough tooling to discover storage, load drivers, unlock encrypted devices and mount the real root filesystem.4142Adding Dropbear changes the boot path to this:4344```text45UEFI / firmware46 -> GRUB loads the kernel and initramfs47 -> initramfs loads the NIC driver and configures an IP address48 -> Dropbear starts and accepts a public-key SSH login49 -> cryptroot-unlock asks for the LUKS passphrase50 -> the encrypted root volume opens51 -> Ubuntu switches to the real root filesystem52 -> the initramfs Dropbear process disappears53 -> normal system services, including OpenSSH, start54```5556That final handover is important. The early SSH server exists only to get the machine across the encrypted-root gap. It is not the SSH service I use after boot.5758## Before changing anything5960I made sure I had all of the following before starting:6162- A working fallback console. My plan B was the VM console in vCenter; on physical or hosted hardware, the equivalent might be IPMI, iDRAC, iLO or a hosting-provider serial console.63- A wired Ethernet connection. Wi-Fi in the initramfs is possible, but firmware, authentication and roaming make it a much larger job.64- Either a DHCP reservation or a known static address for the early-boot interface.65- The name of the wired interface, from `ip link`.66- A second computer from which to test the SSH connection.67- A current backup, because this is boot configuration and optimism is not a recovery plan.6869The examples below use port `2222` for the initramfs service. Keeping it separate from the normal OpenSSH port makes the two host identities obvious and avoids confusing entries in `known_hosts`.7071I did not appreciate that choice when I followed the first tutorial I found. "Surely this is unnecessary," I thought. Then I tried using port 22, hit the host-key warning caused by Dropbear and OpenSSH presenting different keys for the same host, and it all became obvious. OpenSSH records host keys by host and port, so `[server]:2222` gives the temporary boot environment its own identity without teaching the client to ignore host-key checking.7273## 1. Install the initramfs packages7475Install Dropbear's initramfs integration and the cryptsetup hooks:7677```bash78sudo apt update79sudo apt install dropbear-initramfs cryptsetup-initramfs80```8182If APT cannot find `dropbear-initramfs`, enable Ubuntu's `universe` component first:8384```bash85sudo add-apt-repository universe86sudo apt update87sudo apt install dropbear-initramfs cryptsetup-initramfs88```8990The package creates dedicated Dropbear host keys under `/etc/dropbear/initramfs/`. These are deliberately different from the OpenSSH keys used by the fully booted system.9192One Ubuntu 26.04 detail is worth highlighting: the current configuration directory is:9394```text95/etc/dropbear/initramfs/96```9798Many older guides use `/etc/dropbear-initramfs/`. That was the old location and is an easy way to spend an hour editing a file that never reaches the initramfs.99100## 2. Create a dedicated unlock key101102I generated a separate key on my admin workstation rather than reusing my everyday SSH identity:103104```bash105ssh-keygen -t ed25519 -a 64 \106 -f ~/.ssh/luks-unlock \107 -C "LUKS remote unlock"108```109110This creates:111112```text113~/.ssh/luks-unlock # private key - keep this on the admin machine114~/.ssh/luks-unlock.pub # public key - copy this to the server115```116117I gave the private key a passphrase. The server must never receive that private key; it needs only the contents of the `.pub` file.118119## 3. Authorise only the unlock command120121On the server, create or edit the initramfs authorised-keys file:122123```bash124sudo install -d -m 0700 /etc/dropbear/initramfs125sudoedit /etc/dropbear/initramfs/authorized_keys126```127128Paste the public key as one line, but put these restrictions in front of it:129130```text131no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="/bin/cryptroot-unlock" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... LUKS remote unlock132```133134The `AAAAC3...` portion must be the real public key from `~/.ssh/luks-unlock.pub`, not the abbreviated example above.135136Then fix the permissions:137138```bash139sudo chmod 0600 /etc/dropbear/initramfs/authorized_keys140```141142The forced command is an important guardrail. A successful login cannot choose an arbitrary shell command; Dropbear runs `/bin/cryptroot-unlock` instead. Port, agent and X11 forwarding are disabled as well. I still get the interactive terminal that `cryptroot-unlock` needs for the passphrase prompt.143144## 4. Lock down Dropbear and move it to port 2222145146Edit the current initramfs configuration file:147148```bash149sudoedit /etc/dropbear/initramfs/dropbear.conf150```151152Set the options to:153154```bash155DROPBEAR_OPTIONS="-p 2222 -s -j -k"156```157158Those flags select port 2222, disable password authentication, disable local forwarding and disable remote forwarding. The initramfs package already disables password logins, but I prefer the intent to be visible in the configuration too.159160Changing the port is not a security boundary. It separates the boot-time and normal SSH services; the key restrictions and network controls provide the actual protection.161162### What I actually wanted: port 22 all the way through163164Port 2222 neatly solved the host-key problem, but I still wanted Dropbear and OpenSSH to use port 22. They never listen at the same time: Dropbear owns the port while the machine is in the initramfs, then disappears before the normal OpenSSH service starts. There is no port collision.165166The real problem was identity. Dropbear and OpenSSH had different host keys, so an SSH client connecting to the same host on the same port quite correctly treated the change as suspicious. I needed both daemons to present the same host keys.167168Simply copying the OpenSSH private-key files does not work because OpenSSH and Dropbear store private keys in different formats. The [`dropbearconvert`](https://manpages.ubuntu.com/manpages/resolute/man1/dropbearconvert.1.html) tool converts the existing OpenSSH keys into Dropbear's binary format.169170I backed up the original Dropbear initramfs keys, then converted the standard Ubuntu host keys:171172```bash173sudo dropbearconvert openssh dropbear \174 /etc/ssh/ssh_host_rsa_key \175 /etc/dropbear/initramfs/dropbear_rsa_host_key176177sudo dropbearconvert openssh dropbear \178 /etc/ssh/ssh_host_ecdsa_key \179 /etc/dropbear/initramfs/dropbear_ecdsa_host_key180181sudo dropbearconvert openssh dropbear \182 /etc/ssh/ssh_host_ed25519_key \183 /etc/dropbear/initramfs/dropbear_ed25519_host_key184185sudo chmod 0600 \186 /etc/dropbear/initramfs/dropbear_rsa_host_key \187 /etc/dropbear/initramfs/dropbear_ecdsa_host_key \188 /etc/dropbear/initramfs/dropbear_ed25519_host_key189```190191A default Ubuntu installation normally has all three keys. If one of the OpenSSH source files does not exist, skip that conversion rather than inventing a replacement. OpenSSH host keys are normally unencrypted, which matters because `dropbearconvert` cannot read an encrypted private key.192193I then changed `/etc/dropbear/initramfs/dropbear.conf` to use port 22:194195```bash196DROPBEAR_OPTIONS="-p 22 -s -j -k"197```198199After rebuilding the image, the `hostvars` error I had been seeing during the initramfs rebuild disappeared as well:200201```bash202sudo update-initramfs -u -k all203```204205I checked the Ed25519 fingerprints from both formats to confirm that the conversion had preserved the same key:206207```bash208sudo dropbearkey -y \209 -f /etc/dropbear/initramfs/dropbear_ed25519_host_key210211sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub212```213214With the same host identity on both sides of the handover, the client can use port 22 before and after the root volume unlocks without a host-key warning. The unlock connection no longer needs `-p 2222`, and its SSH config does not need a `Port 2222` line.215216There is a genuine trade-off here. Reusing the keys means private host-key material for the normal OpenSSH service is copied into the initramfs, which normally sits in unencrypted `/boot`. The package deliberately generates separate initramfs keys by default for exactly this reason. If exposing the main server identity there is unacceptable, port 2222 with separate keys and a separate `known_hosts` file remains the better design.217218The rest of this walkthrough uses port 2222 because it is the safer general-purpose default. The shared-key port 22 setup above is the variation I ultimately wanted.219220## 5. Give the initramfs a network address221222Dropbear is not useful until the initramfs can configure the network. The cleanest arrangement for my use case was DHCP plus a reservation on the router, so the server received the same early-boot address every time.223224Edit GRUB's defaults:225226```bash227sudoedit /etc/default/grub228```229230Add `ip=dhcp` to the existing value of `GRUB_CMDLINE_LINUX`. Preserve any arguments already there. A simple configuration might look like:231232```bash233GRUB_CMDLINE_LINUX="ip=dhcp"234```235236Then rebuild the GRUB configuration:237238```bash239sudo update-grub240```241242On a machine with several network interfaces, specify the interface explicitly. For example:243244```text245ip=:::::enp2s0:dhcp246```247248For a static address, the kernel parameter has this shape:249250```text251ip=<client-ip>:<server-ip>:<gateway>:<netmask>:<hostname>:<interface>:<autoconf>252```253254This example assigns `192.0.2.50` to `enp2s0` without autoconfiguration:255256```text257ip=192.0.2.50::192.0.2.1:255.255.255.0:cryptbox:enp2s0:none258```259260The `192.0.2.0/24` range is reserved for documentation. Replace every address and the interface name with values from the real network. The Linux kernel's [boot-time IP configuration documentation](https://docs.kernel.org/admin-guide/nfs/nfsroot.html) has the full field definition.261262The normal Netplan configuration does not solve this stage of boot because Netplan lives on the encrypted root filesystem. The address has to come from the kernel command line or other configuration included in the initramfs.263264## 6. Rebuild the initramfs265266Every change under `/etc/dropbear/initramfs/` must be copied into a new initramfs image:267268```bash269sudo update-initramfs -u -k all270```271272Do not skip this. Editing the source files changes nothing about the initramfs already stored in `/boot`.273274I checked the image for the important pieces before rebooting:275276```bash277sudo lsinitramfs /boot/initrd.img-"$(uname -r)" \278 | grep -E 'dropbear|authorized_keys|cryptroot-unlock'279```280281It is also useful to record the fingerprint of the initramfs Ed25519 host key:282283```bash284sudo dropbearkey -y \285 -f /etc/dropbear/initramfs/dropbear_ed25519_host_key286```287288I kept that fingerprint where I could compare it during the first connection. The initramfs host key is not supposed to match the normal OpenSSH host key.289290## 7. Reboot and unlock it291292For the first test I kept the server console open, started a continuous ping from another machine and rebooted:293294```bash295sudo reboot296```297298Once the machine reached the LUKS prompt and the early-boot address responded, I connected from the admin workstation:299300```bash301ssh -t \302 -p 2222 \303 -i ~/.ssh/luks-unlock \304 -o IdentitiesOnly=yes \305 -o UserKnownHostsFile=~/.ssh/known_hosts-initramfs \306 root@192.0.2.50307```308309On the first connection, I compared the presented host-key fingerprint with the one recorded before the reboot. After accepting it, the forced command displayed the LUKS prompt. I entered the normal disk passphrase; it was not echoed to the screen.310311When the volume unlocked, the SSH session ended and boot continued. A short time later the normal OpenSSH service appeared on port 22.312313For repeat use, I added a client-side shortcut to `~/.ssh/config`:314315```sshconfig316Host myserver-unlock317 HostName 192.0.2.50318 User root319 Port 2222320 IdentityFile ~/.ssh/luks-unlock321 IdentitiesOnly yes322 UserKnownHostsFile ~/.ssh/known_hosts-initramfs323```324325The whole recovery procedure then became:326327```bash328ssh -t myserver-unlock329```330331## If the connection does not arrive332333Early boot is a small environment, so the diagnostic list is mercifully short.334335### The host never answers336337Check the console first. If it is waiting for the LUKS passphrase but does not have an address, confirm:338339- `ip=...` appears in `/proc/cmdline` after a successful local boot.340- The initramfs interface name matches `ip link`.341- The DHCP server has a lease for the wired NIC's MAC address.342- The selected network can reach the server before its normal firewall and VPN services exist.343- The NIC driver and any required firmware are present in the initramfs.344345Ubuntu normally includes a broad set of storage and network modules, but unusual adapters can still need help. The Dropbear package documentation recommends adding the required driver module name to `/etc/initramfs-tools/modules`, then rebuilding the initramfs again.346347### SSH says permission denied348349Confirm that the public key is one unbroken line in `/etc/dropbear/initramfs/authorized_keys`, its permissions are `0600`, the containing directory is not writable by other users and the client is using the matching private key. Rebuild the initramfs after every key change.350351### `cryptroot-unlock` is missing352353Make sure `cryptsetup-initramfs` is installed and visible in the `lsinitramfs` output. The package supplies the unlock helper and the hooks that copy it into the boot image.354355### The host key has changed356357Do not blindly switch off host-key checking. A package reinstall, deliberate host-key regeneration or rebuilt machine can explain the change, but verify the new fingerprint through the console before removing the old entry from `~/.ssh/known_hosts-initramfs`.358359### There is more than one encrypted volume360361With a terminal attached, `cryptroot-unlock` continues prompting until the initramfs has unlocked all required encrypted devices. If a non-root encrypted volume is not required during early boot, it may be handled later by the normal system instead; check its `/etc/crypttab` options.362363## The security trade-off364365This setup does not make the server automatically unlock itself. The LUKS passphrase remains with me and travels through an authenticated, encrypted SSH session only when the machine needs it.366367It does, however, add an SSH listener before the normal operating system and its firewall have started. I would not expose port 2222 directly to the public Internet. On a remote site, I would restrict it with an upstream firewall, management network or VPN provided by the router rather than depending on a VPN service stored inside the still-locked root filesystem.368369There is another subtle point: the initramfs and its Dropbear host private key normally live in unencrypted `/boot`. The LUKS passphrase is not stored there, but somebody who can replace the kernel or initramfs can create a fake unlock prompt that captures it. Secure Boot, controlled physical access and careful verification of unexpected host-key changes all matter. Remote unlocking solves an availability problem; it does not remove the need to trust the boot chain.370371My minimum controls are:372373- Public-key authentication only.374- A dedicated, passphrase-protected client key.375- A forced `cryptroot-unlock` command for that key.376- Forwarding disabled in both the key and daemon configuration.377- A separate port and `known_hosts` file for the initramfs identity.378- Upstream network restrictions.379- Console access for recovery and first-boot verification.380- Regular patching and an initramfs rebuild after configuration changes.381382## Where else Dropbear is useful383384Remote LUKS unlock is a particularly satisfying use of Dropbear, but it is not the only one.385386### Routers and embedded devices387388This is Dropbear's traditional home. Its small binary, low memory use and configurable feature set suit routers, access points, appliances and other systems where installing a full OpenSSH stack may be wasteful. OpenWrt is probably where many administrators first meet it.389390### A headless initramfs rescue shell391392The same early SSH path can help diagnose storage discovery, broken LVM assembly, missing kernel modules or failed root mounts on a machine with no useful local console. I would use a separate, carefully restricted recovery key if I wanted an actual shell rather than weakening the LUKS-only key above.393394### Recovery and installation images395396Small recovery systems, custom installers and read-only maintenance images often need remote access without carrying a large userland. Dropbear can provide enough SSH for diagnosis, scripted provisioning or file transfer.397398### Small single-board computers399400Modern boards usually have enough resources for OpenSSH, but Dropbear remains useful when the root filesystem is tiny, storage writes are expensive or the system is deliberately stripped down.401402### Temporary maintenance access403404Dropbear can run standalone or under another service supervisor, which makes it useful as a short-lived maintenance daemon on specialist Unix systems. It still needs the same patching, key management and exposure decisions as any other SSH server.405406It is sometimes suggested as a way to put SSH inside an application container. I generally would not do that. A container is usually easier to inspect with the runtime's exec mechanism, and adding an SSH daemon creates another credential and patching surface. Small does not automatically mean appropriate.407408## A small tool in exactly the right place409410The clever part of this arrangement is not SSH itself. It is putting just enough SSH in the few seconds of boot where the normal server cannot possibly help.411412LUKS still does its job. The passphrase is still required. The server can still reboot without somebody standing beside it. Dropbear simply gives that somebody a narrow, authenticated path to the right prompt.413414That is a good systems tool: small, slightly obscure and extremely useful at precisely the moment everything larger is still locked away.415416---417418**Further reading:**419420- [Dropbear SSH project page](https://matt.ucc.asn.au/dropbear/dropbear.html)421- [Ubuntu 26.04 `dropbear-initramfs` package](https://packages.ubuntu.com/resolute/all/dropbear-initramfs)422- [Ubuntu 26.04 Dropbear manual](https://manpages.ubuntu.com/manpages/resolute/man8/dropbear.8.html)423- [Ubuntu 26.04 `dropbearconvert` manual](https://manpages.ubuntu.com/manpages/resolute/man1/dropbearconvert.1.html)424- [Current Debian/Ubuntu initramfs integration notes](https://sources.debian.org/src/dropbear/2025.89-1~deb13u1/debian/README.initramfs)425- [Linux kernel boot-time IP configuration](https://docs.kernel.org/admin-guide/nfs/nfsroot.html)426