Remote LUKS Unlocking with Dropbear SSH
Learn how to remotely unlock LUKS encrypted LVM volumes using Dropbear SSH on Ubuntu Server. This comprehensive guide covers everything from installing requirements to configuring Dropbear SSH
- Remote unlocking LUKS encrypted LVM using Dropbear SSH in
Ubuntu Server 22.04.3 LTS
Install Requirements
Configure /etc/initramfs-tools/initramfs.conf
Create / Generate Dropber Keys
Note: host keys are already present, as they were automatically generated during the installation of the dropbear package, so there is no need to create new ones as other guides tell you to do
Script: Create cleanup.sh
Main Script: Unlock the LUKS encrypted LVM, create the initramfs hook
cat << 'END_SCRIPT' > /etc/initramfs-tools/hooks/crypt_unlock.sh
#!/bin/sh
PREREQ="dropbear"
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. "${CONFDIR}/initramfs.conf"
. /usr/share/initramfs-tools/hook-functions
if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/crypttab" ] ; then
cat > "${DESTDIR}/bin/unlock" << 'INNER_EOF'
#!/bin/sh
if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then
kill "$(ps | grep cryptroot | grep -v "grep" | awk '{print $1}')"
# following line kill the remote shell right after the passphrase has
# been entered.
kill -9 "$(ps | grep "\-sh" | grep -v "grep" | awk '{print $1}')"
exit 0
fi
exit 1
INNER_EOF
chmod 755 "${DESTDIR}/bin/unlock"
mkdir -p "${DESTDIR}/lib/unlock"
cat > "${DESTDIR}/lib/unlock/plymouth" << 'INNER_EOF'
#!/bin/sh
[ "$1" == "--ping" ] && exit 1
/bin/plymouth "$@"
INNER_EOF
chmod 755 "${DESTDIR}/lib/unlock/plymouth"
echo "To unlock root-partition run 'unlock'" >> "${DESTDIR}/etc/motd"
fi
END_SCRIPT
Make cleanup.sh and crypt_unlock.sh executable
Optional: Samsung Laptop - Fix i915 issues during boot with gpu driver
Disable dropbear as soon as possible after our root unlock
Note: This is not necessary if
OpenSSHwas already installed.
Client: Configure SSH Client
| Option | Description |
|---|---|
-I 600 |
Disconnect the session if no traffic is transmitted or received for 600 seconds |
-j |
Disable local port forwarding |
-k |
Disable remote port forwarding |
-p 2222 |
Listen on port 2222 |
-s |
Disable password logins |
Set DROPBEAR_OPTIONS to listening on port 2222
Append ifconfig to 0.0.0.0 to avoid internet/resolve.conf issues
Upgrade Initramfs / Grub configurations and reboot
Client: Connect to server and unlock luks container (rootfs)
Reference(s)
- https://www.dwarmstrong.org/remote-unlock-dropbear/
- https://openwrt.org/docs/guide-user/base-system/dropbear ' https://forum.archive.openwrt.org/viewtopic.php?id=10417
- https://github.com/ceremcem/unlock-luks-partition
- https://maruel.ca/post/remote-luks-unlock/
- https://www.lisenet.com/2013/luks-add-keys-backup-and-restore-volume-header/
- https://askubuntu.com/questions/1076305/dropbear-initramfs-on-ubuntu-18-04
- https://stinkyparkia.wordpress.com/2014/10/14/remote-unlocking-luks-encrypted-lvm-using-dropbear-ssh-in-ubuntu-server-14-04-1-with-static-ipst/
- https://unix.stackexchange.com/questions/5017/ssh-to-decrypt-encrypted-lvm-during-headless-server-boot
- https://github.com/chadoe/luks-triple-unlock
- https://askubuntu.com/q/620136
- https://matt.ucc.asn.au/dropbear/dropbear.html
- https://gist.github.com/mariodpros/3129b40038be5fbca0e4
- https://www.pbworks.net/ubuntu-guide-dropbear-ssh-server-to-unlock-luks-encrypted-pc/